# API Key and Authentication

> The i14 API accepts Bearer and x-api-key authentication. Learn how to create an API key, add it to your requests, and handle auth errors like 401 and 403.

Source: https://i14.ai/docs/authentication/

Send your i14 key as a Bearer token in the `Authorization` header, or as the value of the `x-api-key` header. The API accepts either header on OpenAI-compatible routes and [Anthropic Messages routes](https://i14.ai/docs/api-reference/messages/). The token is an API key that you generate from the i14 developer platform. Without a valid key the API returns a `401` error and discards the request - no partial processing occurs. This page shows you how to get a key, attach it to requests, keep it secure, and interpret authentication errors when they arise.

## Get your API key

1. Log in or create an account on the [i14 Platform](https://platform.i14.ai/) with your email address or Google account.
2. Open **API Keys**.
3. If you have a referral code, click **Redeem a code** and enter it.
4. Click **Create key**.
5. Copy the key right away - the dashboard shows the full value only once.

No referral code? Join the waitlist.

Keys are scoped to the models your account has access to. If your key does not have access to a specific model, the API returns a `403` error for that model even if the key is otherwise valid.

## Pass Your Key in Requests

Most OpenAI clients send the key as a Bearer token:

```http
Authorization: Bearer YOUR_API_KEY
```

If your client uses `x-api-key`, pass the same i14 key in that header instead. Send one header per request. If you send both, the API uses the Bearer credential when it is present and correctly formatted.

* cURL

  macOS and Linux (bash or zsh)

  ```bash
  curl https://api.i14.ai/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $I14_API_KEY" \
    -d '{
      "model": "i14-sugarglider-nemotron3-super-120b-v1",
      "messages": [
        { "role": "user", "content": "Your message here" }
      ],
      "max_tokens": 2048
    }'
  ```

* Python

  ```python
  import os
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.i14.ai/v1",
      api_key=os.environ["I14_API_KEY"],
  )

  response = client.chat.completions.create(
      model="i14-sugarglider-nemotron3-super-120b-v1",
      messages=[{"role": "user", "content": "Your message here"}],
      max_tokens=2048,
  )

  print(response.choices[0].message.content)
  ```

Replace `Your message here` with your own prompt.

## Keep Your Key Safe

Your API key authorizes the inference access granted to it. Follow these practices to protect it:

* **Use environment variables.** Store the key in `I14_API_KEY` (or any name you choose) and read it at runtime. Never hard-code it in source files.
* **Keep it out of version control.** Add `.env` files and any file containing secrets to your `.gitignore`. If you use a secrets scanner such as `git-secrets` or GitHub secret scanning, enable it on every repository that touches the key.
* **Rotate immediately if exposed.** If you suspect your key has been leaked - for example, committed to a public repo - go to the dashboard, revoke the key, and create a new one. Old keys stop working as soon as you revoke them.
* **Create per-environment keys.** Use separate keys for development, staging, and production so you can revoke one without affecting the others.

> **Caution**
>
> If you accidentally push an API key to a public repository, revoke it from the dashboard right away. Treat any exposed key as compromised even if you delete the commit, because git history can be cached by third-party indexers.

## Authentication Errors

The i14 API returns standard HTTP status codes for authentication and authorization failures. The OpenAI-style response has a JSON `error` object with a `message`, a `type`, and a machine-readable `code`. Anthropic Messages routes use the [Anthropic error format](https://i14.ai/docs/api-reference/messages/#count-input-tokens).

```json
{
  "error": {
    "message": "Model 'example-model' is not available to this API key.",
    "type": "permission_error",
    "code": "model_not_allowed"
  }
}
```

| Status             | `code`              | Meaning                                           | Common Cause                                                                                                                                                                          |
| ------------------ | ------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `401 Unauthorized` | `missing_api_key`   | The request could not be authenticated.           | Neither header contains a key. If using `Authorization`, include the `Bearer` prefix.                                                                                                 |
| `401 Unauthorized` | `invalid_api_key`   | The request could not be authenticated.           | The key is wrong or has been revoked.                                                                                                                                                 |
| `403 Forbidden`    | `model_not_allowed` | The request was authenticated but not authorized. | Your key does not have access to the requested model, or the model ID is misspelled. [List models](https://i14.ai/docs/api-reference/models/) to check which IDs your key can access. |

When you receive a `401`, check that:

1. You sent either `Authorization: Bearer YOUR_API_KEY` (with a space after `Bearer`) or `x-api-key: YOUR_API_KEY`.
2. You are using a key from [platform.i14.ai](https://platform.i14.ai/) and not a key from another provider.
3. The key has not been revoked in the dashboard.
