zed-industries/zed · error
Token exchange failed (HTTP {}): {body}
Error message
Token exchange failed (HTTP {}): {body} What it means
The OAuth authorization-code exchange at OPENAI_TOKEN_URL returned a non-success HTTP status, so the code could not be redeemed for tokens. The status and body are included; typical causes are an expired/already-used authorization code, a PKCE verifier mismatch, or a redirect_uri mismatch.
Source
Thrown at crates/openai_subscribed/src/openai_subscribed.rs:1218
async fn exchange_code(
client: &Arc<dyn HttpClient>,
code: &str,
verifier: &str,
redirect_uri: &str,
) -> Result<TokenResponse> {
let body = form_urlencoded::Serializer::new(String::new())
.append_pair("grant_type", "authorization_code")
.append_pair("client_id", CLIENT_ID)
.append_pair("code", code)
.append_pair("redirect_uri", redirect_uri)
.append_pair("code_verifier", verifier)
.finish();
let request = HttpRequest::builder()
.method(Method::POST)
.uri(OPENAI_TOKEN_URL)
.header("Content-Type", "application/x-www-form-urlencoded")
.body(AsyncBody::from(body))?;
let mut response = client.send(request).await?;
let mut body = String::new();
smol::io::AsyncReadExt::read_to_string(response.body_mut(), &mut body).await?;
if !response.status().is_success() {
return Err(anyhow!(
"Token exchange failed (HTTP {}): {body}",
response.status()
));
}
serde_json::from_str::<TokenResponse>(&body).context("Failed to parse token response")
}
async fn refresh_token(
client: &Arc<dyn HttpClient>,
refresh_token: &str,View on GitHub (pinned to 5a9b9558db)
Solutions
- Restart the sign-in flow — authorization codes are single-use and expire within minutes
- Check that the system clock is accurate; skewed clocks invalidate code exchange
- Verify redirect_uri and client_id match those registered with the provider
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at crates/openai_subscribed/src/openai_subscribed.rs:1186 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@5a9b9558db (2026-08-20).
Data as JSON: /api/errors/314aa6aa29cf8616.
Report an issue: GitHub.