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

# API Key Authentication for A2Agent Requests

> Create and manage A2Agent API keys from the console. Pass your key as a Bearer token on every request — works with OpenAI and Anthropic-compatible clients.

Every request to the A2Agent API must be authenticated with an API key. Keys are created in the console, scoped to your account, and billed against your prepaid balance. You can create multiple keys — for example, one per project or environment — and revoke any of them independently at any time.

## Creating an API Key

<Steps>
  <Step title="Log In">
    Sign in to your account at [https://a2agent.me/login](https://a2agent.me/login).
  </Step>

  <Step title="Navigate to API Keys">
    In the console sidebar, click **API Keys** to open the key management page.
  </Step>

  <Step title="Create a New Key">
    Click **Create Key**. Optionally enter a descriptive label (for example, `production` or `dev-laptop`) to help you identify the key later.
  </Step>

  <Step title="Copy the Key Value">
    The full key is displayed exactly once immediately after creation. Copy it to a secure location such as a password manager or environment variable file. You will not be able to retrieve the full value again after closing this dialog.
  </Step>

  <Step title="Note the Base URL">
    Your base URL is the same for all keys and all models:

    ```text theme={null}
    https://api.a2agent.me
    ```

    Save this alongside your key so you can configure clients in one go.
  </Step>
</Steps>

## Using Your API Key

Pass your API key in the `Authorization` header as a Bearer token on every request.

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

### OpenAI-Compatible Clients

If you use the OpenAI Python or Node.js SDK, set the `base_url` (or `baseURL`) and `api_key` (or `apiKey`) constructor arguments, or export the corresponding environment variables:

```bash theme={null}
export OPENAI_API_KEY="YOUR_API_KEY"
export OPENAI_BASE_URL="https://api.a2agent.me/v1"
```

```python theme={null}
from openai import OpenAI

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

```javascript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "https://api.a2agent.me/v1",
});
```

### Anthropic-Compatible Clients

If you use an Anthropic-compatible client — such as Claude Code or any tool that reads `ANTHROPIC_AUTH_TOKEN` — your A2Agent key works there too. Set the following environment variables:

```bash theme={null}
export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"
export ANTHROPIC_BASE_URL="https://api.a2agent.me"
```

<Tip>
  Most OpenAI SDK clients accept an `OPENAI_API_KEY` environment variable and a `OPENAI_BASE_URL` (or `base_url` constructor argument). Set both to your A2Agent credentials and no other code changes are needed.
</Tip>

## Copying Connection Info

On the API Keys page, each row in the key list has a **Copy Connection Info** button. Clicking it copies your key name, key value, and base URL together in a single formatted block — handy when configuring AI coding clients or sharing setup instructions with a teammate. You never need to hunt for the base URL separately.

## Rotating and Revoking Keys

You can delete any API key from the API Keys page at any time. Deletion is immediate — any request using that key will return a `401 Unauthorized` error after deletion. To rotate a key, create a new one first, update your clients, and then delete the old key once traffic has migrated.

There is no automatic expiry on keys; they remain valid until you delete them.

<Warning>
  Never share your API key publicly or commit it to source control. If a key is exposed, delete it immediately from the API Keys page and create a replacement. All charges incurred before deletion are your responsibility.
</Warning>

## Authentication Errors

| HTTP Status        | Meaning                                           | Common Cause                                                                                                                                     |
| ------------------ | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `401 Unauthorized` | The request could not be authenticated.           | Missing, malformed, or deleted API key. Verify the `Authorization: Bearer …` header is present and the key value is correct.                     |
| `403 Forbidden`    | The request was authenticated but not authorized. | Your account has been suspended or your balance has reached zero. Check your balance on the [Billing](/account/billing) page or contact support. |
