> ## Documentation Index
> Fetch the complete documentation index at: https://docs.a2agent.me/llms.txt
> Use this file to discover all available pages before exploring further.

# A2Agent API Authentication: Keys and Bearer Tokens

> Authenticate every A2Agent API request with a Bearer token. Learn how to pass your key via the OpenAI SDK, Anthropic SDK, or raw HTTP curl commands.

Every request to the A2Agent API must include your API key as a Bearer token in the `Authorization` header. Requests that omit the header or supply an invalid key are rejected before they reach any model. You can create and manage your keys from the [A2Agent dashboard](https://a2agent.me/login).

## Header Format

Include the following header with every API request:

```text theme={null}
Authorization: Bearer YOUR_A2AGENT_KEY
```

Replace `YOUR_A2AGENT_KEY` with the key you copied from your dashboard. Keys are sensitive — treat them like passwords.

## OpenAI SDK

Pass your key to the `api_key` argument when instantiating the client. The SDK attaches the `Authorization` header automatically on every request.

```python title="OpenAI SDK — pass key and base URL" theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_A2AGENT_KEY",
    base_url="https://api.a2agent.me/v1"
)
```

Alternatively, export `OPENAI_API_KEY=YOUR_A2AGENT_KEY` in your shell and omit the `api_key` argument — the SDK will pick it up from the environment.

## Anthropic SDK

The Anthropic SDK reads authentication credentials from two environment variables. Set both before initialising the client:

```python title="Anthropic SDK — set auth environment variables" theme={null}
import anthropic
import os

os.environ["ANTHROPIC_AUTH_TOKEN"] = "YOUR_A2AGENT_KEY"
os.environ["ANTHROPIC_BASE_URL"] = "https://api.a2agent.me"

client = anthropic.Anthropic()
```

## curl

You can authenticate raw HTTP requests by adding the `Authorization` header directly to your `curl` command:

```bash title="curl — Bearer token in Authorization header" theme={null}
curl https://api.a2agent.me/v1/chat/completions \
  -H "Authorization: Bearer YOUR_A2AGENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "deepseek-v4-pro", "messages": [{"role": "user", "content": "Hello"}]}'
```

## Error Responses

If authentication or authorisation fails, the API returns one of the following HTTP status codes:

| Status                  | Meaning                                                                                                                                                         |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `401 Unauthorized`      | The `Authorization` header is missing, malformed, or contains an invalid key. Check that you copied your key correctly and that it has not been revoked.        |
| `403 Forbidden`         | Your account is suspended or your balance is insufficient to complete the request. Top up your balance from your [A2Agent dashboard](https://a2agent.me/login). |
| `429 Too Many Requests` | You have exceeded your request rate limit. Wait briefly and retry, preferably with exponential back-off.                                                        |

<Warning>
  Never expose your API key in client-side JavaScript, mobile app bundles, or public version-control repositories. If a key is accidentally leaked, revoke it immediately from your dashboard and issue a new one.
</Warning>

To create your first key, [sign in to your A2Agent account](https://a2agent.me/login) and navigate to **API Keys**.
