Skip to content

Instantly share code, notes, and snippets.

@hayajo
Created April 1, 2025 03:03
Show Gist options
  • Save hayajo/042c86be5bc8c059c9ae49d42d675377 to your computer and use it in GitHub Desktop.
Save hayajo/042c86be5bc8c059c9ae49d42d675377 to your computer and use it in GitHub Desktop.
Summary URLs using the Anthropic API with curl
#!/bin/sh
ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:?"Please set ANTHROPIC_API_KEY environment variable."}
url=${1:?"Please provide a URL to summarize."}
MODEL=${MODEL:-"claude-3-7-sonnet-20250219"} # see. https://docs.anthropic.com/en/docs/about-claude/models/all-models
payload=$(printf '{
"model": "%s",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "つぎのURLの内容を要約してください。 %s"}
]
}' "$MODEL" "$url")
# "anthropic-version" see. https://docs.anthropic.com/en/api/versioning?q=anthropic-version
curl https://api.anthropic.com/v1/messages \
--header "x-api-key: $ANTHROPIC_API_KEY" \
--header "anthropic-version: 2023-06-01" \
--header "content-type: application/json" \
--data "$payload"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment