| title | Authentication |
|---|---|
| description | Secure your AI Sonar API requests with API keys |
All AI Sonar API requests require an API key.
For OpenAI-compatible endpoints, send it as:
Authorization: Bearer sk-your-api-keyFor Anthropic-compatible /v1/messages requests, you can also use:
x-api-key: sk-your-api-key- Log in to your AI Sonar Dashboard
- Open API Keys
- Create a new key
- Give it a descriptive name
- Copy it immediately because it is shown only once
curl https://api.aisonar.dev/v1/responses \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"input": "Hello!"
}'import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("API_KEY"),
base_url="https://api.aisonar.dev/v1"
)import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.API_KEY,
baseURL: 'https://api.aisonar.dev/v1'
});You can set a usage limit on each API key:
| Setting | Description |
|---|---|
| No Limit | Key uses your account balance without restrictions |
| Fixed Limit | Key stops working after reaching the specified amount |
All AI Sonar API keys start with sk-.
For the /v1/messages endpoint, the Anthropic-style header works as expected:
curl https://api.aisonar.dev/v1/messages \
-H "x-api-key: sk-your-api-key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}]
}'| Status Code | Type | Code | Description |
|---|---|---|---|
| 401 | invalid_api_key |
invalid_api_key |
Missing or invalid API key |
| 401 | expired_api_key |
expired_api_key |
API key has been revoked |
| 402 | insufficient_balance |
insufficient_balance |
Account balance is insufficient |
| 402 | quota_exceeded |
quota_exceeded |
API key usage limit reached |
Example:
{
"error": {
"message": "Invalid API key provided",
"type": "invalid_api_key",
"code": "invalid_api_key"
}
}