router-for-me/CLIProxyAPI · error

failed to read token response: %w

Error message

failed to read token response: %w

What it means

Error "failed to read token response: %w" thrown in router-for-me/CLIProxyAPI.

Source

Thrown at internal/auth/claude/anthropic_auth.go:418

	req, err := http.NewRequestWithContext(ctx, "POST", TokenURL, strings.NewReader(string(jsonBody)))
	if err != nil {
		return nil, fmt.Errorf("failed to create token request: %w", err)
	}
	applyClaudeOAuthAxiosHeaders(req)

	resp, err := o.httpClient.Do(req)
	if err != nil {
		return nil, fmt.Errorf("token exchange request failed: %w", err)
	}
	defer func() {
		if errClose := resp.Body.Close(); errClose != nil {
			log.Errorf("failed to close response body: %v", errClose)
		}
	}()

	body, err := readClaudeOAuthResponseBody(resp)
	if err != nil {
		return nil, fmt.Errorf("failed to read token response: %w", err)
	}
	// log.Debugf("Token response: %s", string(body))

	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("token exchange failed with status %d: %s", resp.StatusCode, string(body))
	}
	// log.Debugf("Token response: %s", string(body))

	var tokenResp tokenResponse
	if err = json.Unmarshal(body, &tokenResp); err != nil {
		return nil, fmt.Errorf("failed to parse token response: %w", err)
	}

	deviceIDs, errDeviceIDs := GenerateDeviceIDPool()
	if errDeviceIDs != nil {
		return nil, errDeviceIDs
	}

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Retry the request; the response body could not be read completely.
  2. Check for proxy or network interruptions between the client and the token endpoint.

When it happens

Trigger: Thrown at internal/auth/claude/anthropic_auth.go:418 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/8490d81682ab1232. Report an issue: GitHub.