Skip to content
ChatGPT API
Documentation

Documentation

Authentication

Last updated:

Everything needed to authenticate a request: where the key comes from, how to send it, how to store it safely, and what each authentication error means.

ChatGPT API authenticates exactly like the official OpenAI API: an API key sent in the Authorization header as a Bearer token, over HTTPS, on every request.

Authorization: Bearer YOUR_API_KEY

Three steps

  1. 1

    Create a key

    Sign up and generate a key in the dashboard. New accounts get $0.25 of test balance.

  2. 2

    Send it as a Bearer token

    Add the Authorization header to every request, or hand the key to the OpenAI SDK and let it build the header for you.

  3. 3

    Point at our base URL

    Replace api.openai.com with our gateway. Paths, request bodies, streaming and error shapes stay identical.

Create API key

Authenticated request

The same authenticated call in three clients. Only the base URL differs from an official OpenAI setup - the SDK builds the Authorization header from the key you pass.

Authenticated request
1curl https://api.llm-gate.tech/v1/responses \2  -H "Content-Type: application/json" \3  -H "Authorization: Bearer $CHATGPT_API_KEY" \4  -d '{5    "model": "gpt-5.4-mini",6    "input": "ping"7  }'
Authenticated request
1import os2from openai import OpenAI3 4client = OpenAI(5    api_key=os.environ["CHATGPT_API_KEY"],6    base_url="https://api.llm-gate.tech/v1",7)8 9response = client.responses.create(model="gpt-5.4-mini", input="ping")10print(response.output_text)
Authenticated request
1import OpenAI from "openai";2 3const client = new OpenAI({4  apiKey: process.env.CHATGPT_API_KEY,5  baseURL: "https://api.llm-gate.tech/v1",6});7 8const response = await client.responses.create({9  model: "gpt-5.4-mini",10  input: "ping",11});12console.log(response.output_text);

Verify a key

The cheapest check is one small request. A 200 response means the key is valid, the base URL is right and the balance is not empty.

Send one request
curl https://api.llm-gate.tech/v1/responses \
  -H "Authorization: Bearer $CHATGPT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-5.4-mini", "input": "ping"}'
200 OK - the key works
{
  "id": "resp_9f2c41a8",
  "object": "response",
  "model": "gpt-5.4-mini",
  "output_text": "pong",
  "usage": {
    "input_tokens": 8,
    "output_tokens": 2,
    "total_tokens": 10
  }
}

A 401 instead means the key is wrong, revoked or the header is malformed. The table below covers each case.

Store the key in an environment variable

Never hardcode a key in source and never ship one to the browser - anything in client-side JavaScript is public. Keep it in an environment variable or your platform's secret manager and read it at runtime.

macOS / Linux
export CHATGPT_API_KEY="your_api_key_here"
Windows (PowerShell)
setx CHATGPT_API_KEY "your_api_key_here"

Authentication errors

Failures return a JSON error body alongside the status code. These are the ones you meet in practice.

StatusMeaningHow to fix
401Missing, malformed or revoked keyCheck the header reads Authorization: Bearer followed by a single space and the key, and that the key was not rotated in the dashboard.
403Valid key, request not allowedUsually a model your account cannot reach yet. Verify the model id against the models page.
404Wrong base URL or pathThe gateway mirrors the official routes under /v1. A 404 normally means the client still points at another host.
429Rate limited or balance spentBack off and retry with exponential jitter. If retries keep failing, top up - an empty balance surfaces here too.

Security

A leaked key is billable to you until it is revoked, so treat it like a password.

Do

  • Keep keys server-side and route browser or mobile traffic through your own backend.
  • Use a separate key per environment so one can be revoked without downtime.
  • Store keys in a secret manager or encrypted CI secrets.
  • Rotate immediately if a key lands in a repository, log or screenshot.

Do not

  • Commit keys to git, including .env files and notebooks.
  • Paste keys into issue trackers, chats or bug reports.
  • Ship keys in front-end bundles, mobile apps or browser extensions.
  • Log the Authorization header in request tracing.

FAQ

Do I need a different key than my OpenAI one?

Yes. ChatGPT API issues its own keys. An official OpenAI key does not authenticate against this gateway, and a gateway key does not work against api.openai.com. Generate a key in the dashboard after signing up.

Do API keys expire?

No. A key stays valid until you revoke or rotate it in the dashboard, and revoking takes effect immediately for new requests.

Can I use the official OpenAI SDKs?

Yes. Set base_url in Python or baseURL in Node to our gateway and pass your key as the api key. The SDK builds the Bearer header itself and every other call site stays unchanged.

Is the key sent on every request?

Yes. The API is stateless, so each request carries its own Authorization header. There is no login call, session cookie or refresh token.

What should I do if a key leaks?

Rotate it in the dashboard right away. The old key stops working immediately, and so does any usage billed to it.

Next steps

Authentication is done. Send a real request or pick the right model.