Skip to navigation
DocsAuthentication

Get started

Authentication and API keys

In short: An API key is one secret that works for every model in both formats; send it as a Bearer token or x-api-key, with optional spend limit, expiry and model list.

Updated View .md
On this page

An API key is the one secret that every request to the API carries. The same key works for every model and for both the OpenAI and the Anthropic request formats, so one key per app or machine is enough.

OpenAI SDKshttps://api.oneaiapikey.com/v1

Anthropic SDKshttps://api.oneaiapikey.com

How do I get an API key?

Create a key on the API keys page of the console:

  1. Sign in and open API keys in the console.
  2. Choose Create key, give it a name (up to 50 characters) and, if you want, a spend limit, an expiry date or a model list. All three are optional and are explained below.
  3. Copy the key from the dialog. It starts with sk-. The console shows the full key only once. If you lose it, revoke it and create a new one.

You can hold up to 1,000 keys per account. Name each key after the app, machine or teammate that uses it, so you can revoke one without breaking the others.

Which headers carry the API key?

Send the key as a Bearer token, or in x-api-key on the two endpoints that accept it:

Header Accepted on Used by
Authorization: Bearer sk-… Every endpoint OpenAI SDKs, LangChain, Vercel AI SDK, most tools
x-api-key: sk-… /v1/messages and /v1/models only Anthropic SDKs, Claude Code

The gateway accepts the key with or without the sk- prefix. Copying it exactly as the console shows it avoids mistakes.

# OpenAI format: Bearer token
curl https://api.oneaiapikey.com/v1/chat/completions \
  -H "Authorization: Bearer $ONEAIAPIKEY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-6-luna:free", "messages": [{"role": "user", "content": "Hi"}]}'

# Anthropic format: x-api-key (Bearer works too)
curl https://api.oneaiapikey.com/v1/messages \
  -H "x-api-key: $ONEAIAPIKEY_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen-qwen3.8-27b:free", "max_tokens": 256, "messages": [{"role": "user", "content": "Hi"}]}'
import os
from openai import OpenAI
import anthropic

# The SDK sends "Authorization: Bearer <key>"
openai_client = OpenAI(base_url="https://api.oneaiapikey.com/v1", api_key=os.environ["ONEAIAPIKEY_API_KEY"])

# The SDK sends "x-api-key: <key>"; no /v1 in the base URL
claude_client = anthropic.Anthropic(base_url="https://api.oneaiapikey.com", api_key=os.environ["ONEAIAPIKEY_API_KEY"])
import OpenAI from "openai";
import Anthropic from "@anthropic-ai/sdk";

const openai = new OpenAI({ baseURL: "https://api.oneaiapikey.com/v1", apiKey: process.env.ONEAIAPIKEY_API_KEY });

// No /v1 in the base URL: the SDK adds /v1/messages itself
const claude = new Anthropic({ baseURL: "https://api.oneaiapikey.com", apiKey: process.env.ONEAIAPIKEY_API_KEY });

Check that a key works

Listing models is free and is the quickest test. A working key returns HTTP 200 and the models it may call:

Terminal
curl -s https://api.oneaiapikey.com/v1/models \
  -H "Authorization: Bearer $ONEAIAPIKEY_API_KEY"

A missing, mistyped, disabled, expired or used-up key returns the same response. The gateway does not say which of these it is, so check the key’s status in the console:

401 response
HTTP/1.1 401 Unauthorized
Content-Type: application/json
X-Request-Id: <request id>

{"error":{"code":"","message":"Invalid token (request id: <request id>)","type":"api_error"}}

Per-key settings

Set these when you create a key, or later with Edit on the API keys page.

How does a spend limit work?

The key stops working once it has spent this many dollars. Your account balance still applies on top, so a key never spends more than the account holds.

  • While some limit is left but less than the gateway’s up-front estimate for a request, that request fails with HTTP 403 and the code pre_consume_token_quota_failed.
  • Once the limit is fully used, the key returns 401 Invalid token, like a disabled key.

Raise the limit, or clear the field to remove it, and the key works again.

What does an expiry date do?

The key stops working at the end of that day, in your local time. After that it returns 401. Edit the key and pick a later date, or clear the field, to switch it back on.

Model list

Choose “Every model your account can use” (the default) or “Only the models I pick”. With a list, a request for any other model fails with HTTP 403 and the message This token has no access to model <id>, and GET /v1/models returns only the picked models.

What is the difference between disable and revoke?

Disable stops a key without deleting it; it returns 401 until you enable it again. Revoke deletes the key for good.

How should I store keys safely?

  • Keep keys in environment variables or a secrets manager, never in source code. The examples in these docs read ONEAIAPIKEY_API_KEY.
  • Never put a key in a browser bundle, a mobile app or a public repository. Anyone who has it can spend your balance. Call the API from your server instead.
  • Use one key per app, machine or teammate, with a spend limit on each, so a leak or a runaway loop costs at most that limit.
  • Set an expiry date on keys for short projects, demos and contractors.

How do I rotate or revoke a key?

Rotate a key by deploying a new one next to the old one, then retiring the old one:

  1. Create a new key and deploy it alongside the old one.
  2. Check the usage page. Once the old key shows no new requests, disable it.
  3. Revoke the old key after a few days without problems.

If a key leaks, disable or revoke it straight away on the API keys page, then create a replacement.

  • Quickstart: your first request in curl, Python and Node.
  • Cost control: spend limits, cheaper models and caching together.
  • Errors: every 401 and 403 the API returns, with fixes.

↑ ↓ moveEnter openEsc close
New accounts$10 credit on sign-up
Claim $10 credit →