curl
Call AnyRouter's OpenAI-compatible API straight from the terminal with curl — for quick tests, scripts, and CI.
curl transfers data with URLs and is the fastest way to test the API by hand, script it, or wire it into CI. AnyRouter is fully OpenAI-compatible, so any curl command that works against OpenAI works here by changing the URL and key.
Before you start
- An AnyRouter API key (prefix
sk-ar-). Create one in the dashboard. - Export it once so the examples below can reference it:
export ANYROUTER_API_KEY="sk-ar-your-key-here"
Make your first call
Send a chat request
curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer $ANYROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-3.5-flash",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Stream the response
Add "stream": true and --no-buffer to receive server-sent events as the response generates.
curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer $ANYROUTER_API_KEY" \
-H "Content-Type: application/json" \
--no-buffer \
-d '{
"model": "anthropic/claude-sonnet-4.6",
"messages": [{"role": "user", "content": "Count to 10, slowly."}],
"stream": true
}'
More recipes
List available models
curl https://anyrouter.dev/api/v1/models \
-H "Authorization: Bearer $ANYROUTER_API_KEY"
Check your credits
curl https://anyrouter.dev/api/v1/credits \
-H "Authorization: Bearer $ANYROUTER_API_KEY"
Health check (no auth required)
curl -A "my-status-probe/1.0" https://anyrouter.dev/api/v1/health
Multi-turn conversation
Pass the full messages array to continue a conversation.
curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer $ANYROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5.4-mini",
"messages": [
{"role": "user", "content": "What is AnyRouter?"},
{"role": "assistant", "content": "AnyRouter is an AI model gateway that lets you access many models through one API."},
{"role": "user", "content": "How do I get started?"}
]
}'
Attribute usage to your app
Set X-Title and X-Source to appear in app rankings and attribute usage to your project.
curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer $ANYROUTER_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Title: My Script" \
-H "X-Source: my-script" \
-d '{
"model": "google/gemini-3.5-flash",
"messages": [{"role": "user", "content": "Summarize this text."}]
}'
See app attribution for how these headers work.
Pipe a prompt from a file
cat prompt.txt | jq -Rsc '{model: "anthropic/claude-sonnet-4.6", messages: [{role: "user", content: .}]}' \
| curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer $ANYROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d @-
Verify
A 200 response with a JSON body containing a choices array means the call succeeded. If you get a 401, re-check that $ANYROUTER_API_KEY is exported and starts with sk-ar-.
Related
- Chat Completions API — the full request schema
- Streaming — how server-sent events work
- Errors — status codes and fixes
- App attribution — the
X-Title/X-Sourceheaders