# Quickstart

Create an API key in the [console](https://www.aixapi.io/keys). One key works with every protocol below. Never expose a key in frontend code or a public repository.

## Base URLs

| SDK | Base URL |
|---|---|
| OpenAI | `https://www.aixapi.io/v1` |
| Anthropic | `https://www.aixapi.io` |

## Authentication

`Authorization: Bearer <API key>` or `x-api-key: <API key>` on every endpoint.

## First request

```python
from openai import OpenAI

client = OpenAI(base_url="https://www.aixapi.io/v1", api_key="sk-...")
resp = client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
```

```python
import anthropic

client = anthropic.Anthropic(base_url="https://www.aixapi.io", api_key="sk-...")
msg = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)
```

```bash
curl https://www.aixapi.io/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet-4-6", "messages": [{"role": "user", "content": "Hello"}]}'
```

## Endpoints

| Method | Path | Use |
|---|---|---|
| GET | `/v1/models` | Models available to the current key |
| POST | `/v1/chat/completions` | OpenAI Chat Completions |
| POST | `/v1/responses` | OpenAI Responses |
| POST | `/v1/messages` | Anthropic Messages |
| POST | `/v1/embeddings` | Embeddings |
| POST | `/v1/images/generations` | Image generation |

## Models

Model IDs and prices are listed in the [Model hub](https://www.aixapi.io/model-plaza). Without an API key, `GET https://www.aixapi.io/api/v1/public/pricing` returns every public model with its USD price per million tokens.

## Errors

| HTTP | Meaning | Action |
|---|---|---|
| 400 | Invalid request body or model parameter | Check the JSON, model name and protocol fields |
| 401 | API key missing or invalid | Check `Authorization` or `x-api-key` |
| 429 | Rate or quota limit reached | Reduce concurrency and check the key's quota |
| 500 | Temporary upstream or gateway failure | Retry later |
