# API Key Management

<table data-header-hidden data-full-width="true"><thead><tr><th width="185.762939453125" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top"><a href="#create-an-api-key">Create a new API key</a></td><td valign="top"><mark style="color:$warning;"><strong><code>POST</code></strong></mark> <code>https://api.aimlapi.com/v1/keys</code></td></tr><tr><td valign="top"><a href="#list-api-keys">List API keys</a></td><td valign="top"><mark style="color:$success;"><strong><code>GET</code></strong></mark> <code>https://api.aimlapi.com/v1/keys</code></td></tr><tr><td valign="top"><a href="#get-the-api-key">Get the API key</a></td><td valign="top"><mark style="color:$success;"><strong><code>GET</code></strong></mark> <code>https://api.aimlapi.com/v1/key</code></td></tr><tr><td valign="top"><a href="#update-an-api-key">Update an API key</a></td><td valign="top"><mark style="color:purple;"><strong><code>PATCH</code></strong></mark> <code>https://api.aimlapi.com/v1/keys/{prefix}</code></td></tr><tr><td valign="top"><a href="#delete-an-api-key">Delete an API key</a></td><td valign="top"><mark style="color:$danger;"><strong><code>DELETE</code></strong></mark> <code>https://api.aimlapi.com/v1/keys/{prefix}</code></td></tr></tbody></table>

{% hint style="warning" %}
Before you start you should create [a managment key](/faq/how-can-i-work-with-my-api-keys.md#management-keys).
{% endhint %}

### Create a new API key

Copy the created key and store it in a secure location. If the key is lost, create a new one.

## POST /v1/keys

>

```json
{"openapi":"3.0.0","info":{"title":"AIML API","version":"1.0.0"},"servers":[{"url":"https://api.aimlapi.com"}],"paths":{"/v1/keys":{"post":{"operationId":"KeysController_createKey_v1","requestBody":{"required":false,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","description":"Optional human-readable name of the API key."},"limit":{"type":"object","description":"Optional spending limit configuration.","properties":{"retention":{"type":"string","description":"Limit period.","enum":["no_reset","day","week","month"]},"threshold":{"type":"number","description":"Spending limit threshold for the selected period, in USD."}}},"scopes":{"type":"array","nullable":true,"description":"List of model access scopes assigned to the key. Defines which categories of models can be called using this API key.","items":{"type":"string","enum":["model:chat","model:responses","model:image","model:audio","model:video","model:embeddings","model:speech","model:ocr"]}}},"additionalProperties":false}}}},"responses":{"200":{"description":"API key creation result","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"name":{"type":"string","nullable":true,"description":"Human-readable, user-defined name for the API key."},"disabled":{"type":"boolean","description":"Indicates whether the key is disabled."},"prefix":{"type":"string","description":"Key prefix. This is the first 8 characters of your API key, visible in the dashboard."},"scopes":{"type":"array","nullable":true,"description":"List of model access scopes assigned to the key. Defines which categories of models can be called using this API key.","items":{"type":"string","enum":["model:chat","model:responses","model:image","model:audio","model:video","model:embeddings","model:speech","model:ocr"]}},"limit":{"type":"object","description":"Applied spending limits.","properties":{"retention":{"type":"string","description":"Limit period.","enum":["no_reset","day","week","month"]},"threshold":{"type":"number","description":"Spending limit threshold for the selected period, in USD"}}},"created_at":{"type":"string","format":"date-time","description":"Creation timestamp (UTC)."},"updated_at":{"type":"string","format":"date-time","description":"Last update timestamp (UTC)."},"monthly_usage":{"type":"number","description":"Current monthly usage amount."},"key":{"type":"string","description":"Full API key value (returned only at creation time)."}},"required":["disabled","prefix","scopes","created_at","updated_at","monthly_usage","key"]}},"required":["data"]}}}}}}}}}
```

***

### List API keys

Returns all API keys for your account, including each key’s settings and metadata.

## GET /v1/keys

>

```json
{"openapi":"3.0.0","info":{"title":"AIML API","version":"1.0.0"},"servers":[{"url":"https://api.aimlapi.com"}],"paths":{"/v1/keys":{"get":{"operationId":"KeysController_listKeys_v1","responses":{"200":{"description":"List of API keys, ordered from oldest to newest","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string","nullable":true,"description":"Human-readable, user-defined name for the API key."},"prefix":{"type":"string","description":"Key prefix. This is the first 8 characters of your API key, visible in the dashboard. You can also obtain this value via the POST method (see the `prefix` field in its response)."},"disabled":{"type":"boolean","description":"Indicates whether the key is disabled."},"scopes":{"type":"array","nullable":true,"description":"List of model access scopes assigned to the key. Defines which categories of models can be called using this API key.","items":{"type":"string","enum":["model:chat","model:responses","model:image","model:audio","model:video","model:embeddings","model:speech","model:ocr"]}},"limit":{"nullable":true,"type":"object","description":"Spending limits configuration (if set).","properties":{"retention":{"type":"string","enum":["no_reset","day","week","month"]},"threshold":{"type":"number","description":"Spending limit threshold for the selected period, in USD."}}},"created_at":{"type":"string","format":"date-time","description":"Creation timestamp (UTC)."},"updated_at":{"type":"string","format":"date-time","description":"Last update timestamp (UTC)."},"monthly_usage":{"type":"number","description":"Current monthly usage amount."}},"required":["disabled","prefix","scopes","created_at","updated_at","monthly_usage"]}}},"required":["data"]}}}}}}}}}
```

***

### Get the API key

Retrieve parameters of the AIMLAPI key used in the request.

## GET /v1/key

>

```json
{"openapi":"3.0.0","info":{"title":"AIML API","version":"1.0.0"},"servers":[{"url":"https://api.aimlapi.com"}],"paths":{"/v1/key":{"get":{"operationId":"KeysController_getLatestKey_v1","responses":{"200":{"description":"Parameters of the latest API key","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"name":{"type":"string","nullable":true,"description":"Human-readable, user-defined name for the API key."},"disabled":{"type":"boolean","description":"Indicates whether the key is disabled."},"prefix":{"type":"string","description":"Key prefix. This is the first 8 characters of your API key, visible in the dashboard. You can also obtain this value via the POST method (see the `prefix` field in its response)."},"scopes":{"type":"array","nullable":true,"description":"List of model access scopes assigned to the key. Defines which categories of models can be called using this API key.","items":{"type":"string","enum":["model:chat","model:responses","model:image","model:audio","model:video","model:embeddings","model:speech","model:ocr"]}},"limit":{"nullable":true,"type":"object","description":"Spending limits configuration (if set).","properties":{"retention":{"type":"string","enum":["no_reset","day","week","month"]},"threshold":{"type":"number","description":"Spending limit threshold for the selected period, in USD."}}},"created_at":{"type":"string","format":"date-time","description":"Creation timestamp (UTC)."},"updated_at":{"type":"string","format":"date-time","description":"Last update timestamp (UTC)."},"monthly_usage":{"type":"number","description":"Current monthly usage amount."}},"required":["disabled","prefix","created_at","updated_at","monthly_usage"]}},"required":["data"]}}}}}}}}}
```

***

### Update an API key

## PATCH /v1/keys/{prefix}

>

```json
{"openapi":"3.0.0","info":{"title":"AIML API","version":"1.0.0"},"servers":[{"url":"https://api.aimlapi.com"}],"paths":{"/v1/keys/{prefix}":{"patch":{"operationId":"KeysController_patchKey_v1","parameters":[{"name":"prefix","in":"path","required":true,"description":"Prefix of the API key to update. Passed in the URL path. This is the first 8 characters of your API key, visible in the dashboard. You can also obtain this value via the GET method (see the `prefix` field in its response).","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","description":"Optional human-readable name of the API key."},"disabled":{"type":"boolean","description":"Enable or disable the API key."},"limit":{"type":"object","description":"Optional spending limit configuration.","properties":{"retention":{"type":"string","description":"Limit period.","enum":["no_reset","day","week","month"]},"threshold":{"type":"number","description":"Spending limit threshold for the selected period, in USD"}}},"scopes":{"type":"array","nullable":true,"description":"List of model access scopes assigned to the key. Defines which categories of models can be called using this API key.","items":{"type":"string","enum":["model:chat","model:responses","model:image","model:audio","model:video","model:embeddings","model:speech","model:ocr"]}}}}}}},"responses":{"200":{"description":"Updated API key parameters","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"name":{"type":"string","nullable":true,"description":"Human-readable, user-defined name for the API key."},"disabled":{"type":"boolean","description":"Indicates whether the key is disabled."},"prefix":{"type":"string","description":"Key prefix. This is the first 8 characters of your API key, visible in the dashboard. You can also obtain this value via the GET method (see the `prefix` field in its response)."},"scopes":{"type":"array","nullable":true,"description":"List of model access scopes assigned to the key. Defines which categories of models can be called using this API key.","items":{"type":"string","enum":["model:chat","model:responses","model:image","model:audio","model:video","model:embeddings","model:speech","model:ocr"]}},"limit":{"nullable":true,"type":"object","description":"Spending limits configuration (if set).","properties":{"retention":{"type":"string","enum":["no_reset","day","week","month"]},"threshold":{"type":"number"}}},"created_at":{"type":"string","format":"date-time","description":"Creation timestamp (UTC)."},"updated_at":{"type":"string","format":"date-time","description":"Last update timestamp (UTC)."},"monthly_usage":{"type":"number","description":"Current monthly usage amount."}},"required":["disabled","prefix","scopes","created_at","updated_at","monthly_usage"]}},"required":["data"]}}}}}}}}}
```

***

### Delete an API key

## DELETE /v1/keys/{prefix}

>

```json
{"openapi":"3.0.0","info":{"title":"AIML API","version":"1.0.0"},"servers":[{"url":"https://api.aimlapi.com"}],"paths":{"/v1/keys/{prefix}":{"delete":{"operationId":"KeysController_postKeys_v1","parameters":[{"name":"prefix","in":"path","required":true,"description":"Prefix of the API key to delete. Passed in the URL path. This is the first 8 characters of the API key you want to delete. Passed in the URL path. This is the first 8 characters of your API key, visible in the dashboard. You can also obtain this value via the GET method (see the `prefix` field in its response).","schema":{"type":"string"}}],"responses":{"200":{"description":"Key deletion result","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"prefix":{"type":"string","description":"Prefix of the deleted API key."},"deleted":{"type":"boolean","description":"Indicates whether the key was successfully deleted."}},"required":["prefix","deleted"]}},"required":["data"]}}}}}}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aimlapi.com/api-references/service-endpoints/api-key-management.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
