Getting started
Read this page as MarkdownIn this section: Personal API 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
- Sign in at askmiles.ai. A free account is enough.
- Open Settings → API keys and choose Create key. Name it for the place it will live.
- Copy the key. It starts with
miles_sk_and is shown once; Miles stores a hash and cannot show it again. - Send one request.
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:
{
"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.
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 for the wallet tools.
When it fails
401with codeinvalid_api_key: the key was revoked or never existed. Mint a new one.403with codeconnections_paused: the account's AI app connections are paused at 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.