# curl

> Call AnyRouter's OpenAI-compatible API from the terminal with curl, for quick tests, scripts and CI.


# Call AnyRouter with curl

Any curl command that works against OpenAI works here with a new URL and key. Create a key (prefix `sk-ar-`) in the [dashboard](https://anyrouter.dev/dashboard/keys) and export it:

```bash
export ANYROUTER_API_KEY="sk-ar-your-key-here"
```

## Chat request

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

A `200` with a `choices` array means it worked. A `401` means `$ANYROUTER_API_KEY` is missing or does not start with `sk-ar-`.

For a multi-turn chat, send the full `messages` array.

## Stream

Add `"stream": true` and `--no-buffer` to receive server-sent events:

```bash
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}'
```

## Other calls

| Call | Command |
|---|---|
| List models | `curl https://anyrouter.dev/api/v1/models -H "Authorization: Bearer $ANYROUTER_API_KEY"` |
| Check credits | `curl https://anyrouter.dev/api/v1/credits -H "Authorization: Bearer $ANYROUTER_API_KEY"` |
| Health (no auth) | `curl -A "my-status-probe/1.0" https://anyrouter.dev/api/v1/health` |

To attribute usage to your project in [app rankings](https://anyrouter.dev/data/apps), add `-H "X-Title: My Script" -H "X-Source: my-script"`.


## Related

- [Chat Completions API](/docs/api-reference/chat-completions.md)
- [Streaming](/docs/guides/streaming.md)
- [Errors](/docs/guides/errors.md)
- [App Attribution](/docs/features/app-attribution.md)
