Zed
How to fix Zed returning 401 or an invalid API key
A 401 means the request reached the AI Code With server and failed at authentication. The problem is the API key itself, its validity, or the account state — not the API URL or Model ID. Zed stores keys in the system keychain; do not put real keys in settings.json.
Start with these checks
The request reached AI Code With, but authentication failed. Verify the keychain API key before changing the API URL or Model ID.
- After sending a message in the Agent Panel, Zed reports 401, Unauthorized, or Invalid API Key.
- The pasted API key is incomplete, has extra spaces or newlines, or is the wrong key
- Open Agent Settings (command agent: open settings) → LLM Providers and select AI Code With / aicodewith
401UnauthorizedInvalid API Key01
Confirm the request reached the server
401 / Unauthorized / Invalid API Key means the HTTP request reached https://api.aicodewith.ai/v1 and was rejected while checking the Authorization header. Do not change the API URL or Model ID yet.
Timeouts, DNS failures, or 404s are address or network problems — use the API URL article first. Follow this page only when the error is explicitly 401.
02
Re-paste the API key in the provider UI
Open Agent Settings → LLM Providers, select the OpenAI-compatible provider you added, clear the API Key field, and paste the full key. Avoid copied newlines, surrounding spaces, or quotes.
Zed writes the key to the system keychain, not settings.json. If you previously put an sk- string in JSON, delete that field and enter the key in the UI instead; otherwise the UI value may never apply.
- 1Open Agent Settings (command agent: open settings) → LLM Providers and select AI Code With / aicodewith
- 2Clear the API Key field and paste the full key again, with no spaces or newlines
03
Verify the key and account, then send a test message
In the AI Code With dashboard, confirm the key is still valid and the account has balance. Expired, disabled, or zero-balance keys also return 401 at authentication.
After saving the provider, pick a model under that provider in the Agent Panel and send a short message. A normal reply with no 401 restores the credential chain. Then match the call by time in usage records.
- 1Clear the API Key field and paste the full key again, with no spaces or newlines
- 2In AI Code With Key Management, confirm the key is active and the account has balance
Copying or saving the provider is not a successful connection. The checkable signals are a real Agent Panel reply and a matching usage-record entry.
If it is still not fixed
Sources
Reconfigure
Return to the integration center and continue the setup steps.
Return to the related setup step