> For the complete documentation index, see [llms.txt](https://docs.apismart.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apismart.ai/troubleshooting/api-key-and-authentication-issues.md).

# API Key and Authentication Issues

Troubleshoot ApiSmart API Key authentication errors, invalid credentials, model access issues, and common authorization problems.

ApiSmart uses API Keys to authenticate API requests.

If a request returns `401` or `403`, check your API Key, authorization header, and model access before retrying.

### 🔑 Check Your Authorization Header

Include your API Key in every authenticated request:

```http
Authorization: Bearer <your-api-key>
```

Example:

```bash
curl https://gw.apismart.ai/v1/models \
  -H "Authorization: Bearer <your-api-key>"
```

Make sure that:

* `Bearer` is included
* There is one space between `Bearer` and the API Key
* The API Key is complete
* No extra quotes or spaces were copied into the key

### 401 — Invalid API Key

If the API returns:

```
401 invalid_api_key
```

the API Key could not be authenticated.

Check that you are using the correct API Key and that your application is sending it in the `Authorization` header.

If necessary, create or manage your credentials from the ApiSmart Console.

For API Key management, see [**Create and Manage API Keys**](/welcome-to-apismart/api-keys/create-and-manage-api-keys.md).

### 403 — Model Access Issues

A `403` response does not always mean that your API Key itself is invalid.

For example:

```
403 model_not_allowed
```

means the API Key was authenticated, but the selected model is not currently available to your account.

Other model-related `403` errors can include:

* `model_not_image_capable` — The model cannot be used with the Image Generation API
* `model_not_video_capable` — The model cannot be used with the Video Generation API
* `AccessDenied` — Access to the requested model or operation was denied

Choose a supported model or contact [**ApiSmart Support**](/help-and-resources/contact-support.md) if you need access.

### 🧩 Verify the Model ID

You can retrieve the current model list with:

```bash
curl https://gw.apismart.ai/v1/models \
  -H "Authorization: Bearer <your-api-key>"
```

Use the returned `data[].id` value exactly as provided.

Model IDs are matched exactly, including periods, hyphens, and version numbers. An incorrectly written model ID can result in an unexpected `503`, so check the model ID carefully before assuming the issue is authentication-related.

### 🔒 Keep Your API Key Secure

Do not:

* Expose API Keys in frontend code
* Commit API Keys to public repositories
* Include full API Keys in screenshots or logs
* Send your full API Key to support

Store API Keys in environment variables or another secure secrets-management system.

For security recommendations, see [**Secure Your API Keys**](/welcome-to-apismart/api-keys/secure-your-api-keys.md).

### ✅ Quick Troubleshooting Checklist

If authentication fails, verify:

* The API Key is correct
* The header uses `Authorization: Bearer <your-api-key>`
* The requested model ID is correct
* The model is available to your API Key
* The selected model supports the API endpoint

For other errors, see [**HTTP Status Codes and API Errors**](/troubleshooting/http-status-codes-and-api-errors.md).

### ➡️ Next Steps

* [**Create and Manage API Keys**](/welcome-to-apismart/api-keys/create-and-manage-api-keys.md)
* [**Secure Your API Keys**](/welcome-to-apismart/api-keys/secure-your-api-keys.md)
* [**Models and Model IDs**](/models-and-pricing/models-and-model-ids.md)
* [**HTTP Status Codes and API Errors**](/troubleshooting/http-status-codes-and-api-errors.md)
