Troubleshooting · Zed

Zed 401 Invalid API Key — OpenAI Provider Settings Fix

Zed's assistant passes the endpoint's 401 through verbatim. Where the key and api_url of the OpenAI provider live in Zed and why they must come from the same issuer.

What you see

HTTP 401
{"error":{"message":"Invalid or missing API key.","type":"invalid_request_error","param":null,"code":"invalid_api_key"}}

Why it happens

  • The key in Zed's OpenAI provider settings and the api_url point at different issuers — a gateway key sent to the default api.openai.com, or vice versa.
  • The key was pasted with whitespace or truncated.
  • An OPENAI_API_KEY environment variable from another provider is set in the environment Zed started from, so Zed sends that key instead of the one you expect.
  • The key was revoked or expired.

How to fix it

  • Set language_models.openai.api_url to https://router.apitoken.sale/v1, and enter that issuer's key in the assistant's OpenAI provider settings.
  • Keep the api_url ending at /v1 — Zed appends the API path itself.
  • Verify the exact pair with curl before changing anything else.

Zed settings.json for this gateway

{
  "language_models": {
    "openai": {
      "api_url": "https://router.apitoken.sale/v1",
      "available_models": [{ "name": "gpt-6.1-terra", "display_name": "GPT-6.1 Terra", "max_tokens": 872000 }]
    }
  }
}

Related searches

  • zed openai api key not working
  • zed 401 unauthorized

FAQ

Where does Zed keep the OpenAI base URL?+
In settings.json under language_models.openai.api_url. The API key itself is entered in the assistant's provider configuration.
Why does my key fail in Zed but work in curl?+
Zed sends it to whatever api_url is configured. If that differs from the URL you curl, the endpoint seeing the key is not the one that issued it.
Do I need an OpenAI account to use GPT models in Zed?+
No — any OpenAI-compatible endpoint works: set api_url to the issuer, use its key, and list the models in available_models.

Skip the broken setup

apiToken.sale serves GPT and Gemini models through OpenAI-compatible, Messages (Anthropic format) and native Gemini endpoints — standard SDKs, one key, one prepaid balance. Point your tool's base URL at it, and the config on this page works as written.