> Fetch https://askmiles.ai/llms.txt first: it indexes every public Miles capability. This file is the markdown twin of https://askmiles.ai/docs/getting-started/personal-key.

# Personal API key

Mint a key in Settings, paste it into an OpenAI client, and ask Miles a question from your own code in four steps.

## Four steps

1. Sign in at askmiles.ai. A free account is enough.
2. Open [Settings → API keys](https://askmiles.ai/settings#api-keys) and choose **Create key**. Name it for the place it will live.
3. Copy the key. It starts with `miles_sk_` and is shown once; Miles stores a hash and cannot show it again.
4. Send one request.

```bash
curl https://askmiles.ai/v1/chat/completions \
  -H "Authorization: Bearer $MILES_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "miles", "messages": [{"role": "user", "content": "Which card should I use at Costco?"}]}'
```

The answer is the one Miles would give on the site, in the OpenAI response shape:

```json
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "miles",
  "choices": [{"index": 0, "message": {"role": "assistant", "content": "At a Costco warehouse, use your Chase Sapphire Reserve…"}, "finish_reason": "stop"}],
  "usage": {"prompt_tokens": 412, "completion_tokens": 186, "total_tokens": 598},
  "miles": {"tools_called": ["get_best_card"], "duration_ms": 9800}
}
```

## With the OpenAI SDK

Point any OpenAI client at the base URL. The SDK's own User-Agent passes Cloudflare; a bare `curl` passes too. A stock `Python-urllib` User-Agent gets an opaque 403 from Cloudflare before Miles sees the request, in plain text rather than the error envelope, so use a client library or set a User-Agent.

```python
from openai import OpenAI

client = OpenAI(base_url="https://askmiles.ai/v1", api_key=MILES_API_KEY)
response = client.chat.completions.create(
    model="miles",
    messages=[{"role": "user", "content": "Which card should I use at Costco?"}],
)
print(response.choices[0].message.content)
```

## What a key is

A key belongs to your Miles account and answers from your wallet. It does not expire; it lives until you revoke it in Settings, and the revoke stops the next call. You can hold up to ten. Every key on one account shares one rate count of 30 requests a minute, so a second key is a second name, not a second allowance.

A key reaches the Chat API only. It is not an MCP credential and it cannot write to your wallet; see [Connect over MCP](https://askmiles.ai/docs/getting-started/mcp) for the wallet tools.

## When it fails

- `401` with code `invalid_api_key`: the key was revoked or never existed. Mint a new one.
- `403` with code `connections_paused`: the account's AI app connections are paused at [Settings → Connected AI Apps](https://askmiles.ai/settings#connected-ai-apps). Turn them back on; the key resumes without re-minting.
- A plain-text 403 with no JSON body: Cloudflare refused the User-Agent. Use the SDK.

Every other case is on the [errors page](https://askmiles.ai/docs/chat-api/errors).
