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

# API keys

> Create and manage API keys for authenticating your requests

API keys authenticate your requests. You can create keys with
different access scopes depending on what each key needs to do, and set an
expiration date to limit how long a key remains valid.

## Create an API key

API keys are managed from the [API Tokens
page](https://console.modular.com/api_tokens) in the console.

#### Go to API Tokens

Open the [API Tokens page](https://console.modular.com/api_tokens) in
the console and click **Create**.

#### Fill in the token details

In the dialog that appears, provide the following:

* **Name**: A short, descriptive name for the token.
* **Description**: Optional context about what the token is used for.
* **Model access**: Toggle on to grant access to all models in your
  organization. Enable this for tokens used to call inference endpoints.
* **Developer access**: Toggle on to grant full API access including cluster
  and deployment management. Enable this for tokens used to manage
  infrastructure programmatically.
* **Expires**: Choose when the token expires. The token cannot be used after
  its expiration date.

#### Submit and record the token

Click **Submit**. Copy the token value immediately; it will not be shown again
after you close the dialog.

All created tokens appear on the API Tokens page. Click **Delete** next to any
token you no longer need.

## Environment variable authentication

Store your API key in an environment variable rather than hard-coding it in
your application. Export it in your shell before running your code:

```bash theme={null}
export MODULAR_API_KEY="your_api_key_here"
```

Then reference it in your requests:

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

client = OpenAI(
    base_url="https://api.modular.com/v1",
    api_key=os.environ["MODULAR_API_KEY"],
)
```
