router-for-me/CLIProxyAPI · error

create Claude OAuth %s request: %w

Error message

create Claude OAuth %s request: %w

What it means

Returned by ClaudeAuth.fetchOAuthControlPlaneJSON when http.NewRequestWithContext rejects the GET to the OAuth control-plane endpoint (ProfileURL https://api.anthropic.com/api/oauth/profile or RolesURL). The endpoints are compile-time constants, so parse failure requires them to be edited to a malformed URL or the ctx to be nil. Pure construction-time guard; no network involved.

Source

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

	req.Header.Set("User-Agent", "axios/1.15.2")
	req.Header.Set("Accept-Encoding", "gzip, compress, deflate, br")
	req.Header.Set("Connection", "close")
	req.Close = true
}

// fetchOAuthControlPlaneJSON issues an Axios-shaped OAuth control-plane GET and
// returns the decoded response body. label names the endpoint in error text.
func (o *ClaudeAuth) fetchOAuthControlPlaneJSON(ctx context.Context, endpoint, accessToken, label string) ([]byte, error) {
	if o == nil || o.httpClient == nil {
		return nil, fmt.Errorf("fetch Claude OAuth %s: HTTP client is nil", label)
	}
	accessToken = strings.TrimSpace(accessToken)
	if accessToken == "" {
		return nil, fmt.Errorf("fetch Claude OAuth %s: access token is empty", label)
	}
	req, errRequest := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
	if errRequest != nil {
		return nil, fmt.Errorf("create Claude OAuth %s request: %w", label, errRequest)
	}
	applyClaudeOAuthAxiosHeaders(req)
	req.Header.Set("Authorization", "Bearer "+accessToken)
	req.Header.Set("Cache-Control", "no-cache")

	resp, errDo := o.httpClient.Do(req)
	if errDo != nil {
		return nil, fmt.Errorf("fetch Claude OAuth %s: %w", label, errDo)
	}
	defer func() {
		if errClose := resp.Body.Close(); errClose != nil {
			log.Errorf("failed to close Claude OAuth %s response body: %v", label, errClose)
		}
	}()
	body, errRead := readClaudeOAuthResponseBody(resp)
	if errRead != nil {
		return nil, fmt.Errorf("read Claude OAuth %s response: %w", label, errRead)
	}

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Fix the malformed endpoint constant (scheme + host must parse)
  2. Pass a non-nil context from the caller
  3. Add a unit test that url.Parse's each endpoint constant
Defensive patterns

Strategy: validation

Validate before calling

if ctx == nil { ctx = context.Background() }
if _, errParse := url.Parse(endpoint); errParse != nil {
    return fmt.Errorf("malformed OAuth endpoint %q", endpoint)
}

Try / catch

if _, err := auth.FetchOAuthProfile(ctx, token); err != nil {
    var urlErr *url.Error
    if errors.As(err, &urlErr) { log.Errorf("endpoint constant misconfigured: %v", err) }
}

Prevention

When it happens

Trigger: Overriding ProfileURL/RolesURL constants with a scheme-less or control-character URL in a fork; passing a nil ctx from a custom caller.

Common situations: Local development pointing api.anthropic.com at a stub with a typo'd URL; rarely or never seen with stock constants.

Related errors


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