AnyRouter

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

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!"}]
  }'

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

curl https://anyrouter.dev/api/v1/models \
  -H "Authorization: Bearer $ANYROUTER_API_KEY"
curl https://anyrouter.dev/api/v1/credits \
  -H "Authorization: Bearer $ANYROUTER_API_KEY"
curl -A "my-status-probe/1.0" https://anyrouter.dev/api/v1/health

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?"}
    ]
  }'

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.

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-.