router-for-me/CLIProxyAPI · error

failed to create token request: %w

Error message

failed to create token request: %w

What it means

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

Source

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

		CodeVerifier: pkceCodes.CodeVerifier,
		State:        state,
	}

	// A state fragment appended to the callback code takes precedence.
	if newState != "" {
		reqBody.State = newState
	}

	jsonBody, err := json.Marshal(reqBody)
	if err != nil {
		return nil, fmt.Errorf("failed to marshal request body: %w", err)
	}

	// log.Debugf("Token exchange request: %s", string(jsonBody))

	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))

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Verify the token endpoint URL is valid and the HTTP client is initialized.
  2. Check the wrapped error for the request construction failure details.

When it happens

Trigger: Thrown at internal/auth/claude/anthropic_auth.go:402 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/5daf7a3244eb52ab. Report an issue: GitHub.