router-for-me/CLIProxyAPI · error

kimi: failed to create refresh request: %w

Error message

kimi: failed to create refresh request: %w

What it means

http.NewRequestWithContext failed while building the refresh-token POST to https://auth.kimi.com/api/oauth/token. As with error 225, all inputs (method, constant URL, encoded form body) are fixed, so this is unreachable in a stock build and would only occur in modified code with an invalid URL.

Source

Thrown at internal/auth/kimi/kimi.go:377

	if err != nil {
		return nil, err
	}
	tokenData, ok := result.(*KimiTokenData)
	if !ok || tokenData == nil {
		return nil, fmt.Errorf("kimi: refresh token failed: invalid single-flight result")
	}
	return tokenData, nil
}

func (c *DeviceFlowClient) refreshTokenSingleFlight(ctx context.Context, refreshToken string) (*KimiTokenData, error) {
	data := url.Values{}
	data.Set("client_id", kimiClientID)
	data.Set("grant_type", "refresh_token")
	data.Set("refresh_token", refreshToken)

	req, err := http.NewRequestWithContext(ctx, http.MethodPost, kimiTokenURL, strings.NewReader(data.Encode()))
	if err != nil {
		return nil, fmt.Errorf("kimi: failed to create refresh request: %w", err)
	}
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Set("Accept", "application/json")
	for k, v := range c.commonHeaders() {
		req.Header.Set(k, v)
	}

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

	bodyBytes, err := io.ReadAll(resp.Body)

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. If running a fork, verify kimiTokenURL parses as an absolute URL
  2. Otherwise report as a bug — the stock binary cannot produce this error
Defensive patterns

Strategy: validation

Validate before calling

if u, err := url.Parse(kimiTokenURL); err != nil || !u.IsAbs() {
    return nil, fmt.Errorf("kimi: misconfigured token URL %q", kimiTokenURL)
}

Prevention

When it happens

Trigger: Forked code that changes kimiTokenURL to an invalid URL string; effectively zero occurrence in the shipped binary.

Common situations: Custom patches introducing a typo in the token URL constant.

Related errors


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