fatedier/frp · error

api status code [%d]

Error message

api status code [%d]

What it means

Returned by Client.do, the shared transport for all SDK calls, whenever the frpc admin API answers with a non-200 status. The message contains only the numeric code, e.g. "api status code [401]", and applies to every endpoint (status, reload, stop, config).

Source

Thrown at pkg/sdk/client/client.go:133

}

func (c *Client) setAuthHeader(req *http.Request) {
	if c.authUser != "" || c.authPwd != "" {
		req.Header.Set("Authorization", httppkg.BasicAuth(c.authUser, c.authPwd))
	}
}

func (c *Client) do(req *http.Request) (string, error) {
	c.setAuthHeader(req)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return "", fmt.Errorf("api status code [%d]", resp.StatusCode)
	}
	buf, err := io.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}
	return string(buf), nil
}

View on GitHub (pinned to 6c8a8d0a97)

Solutions

  1. Decode the status: 401 → set matching webServer credentials on the SDK client; 404 → wrong address or endpoint missing in this frpc version; 500 → inspect frpc logs for the server-side cause.
  2. Confirm webServer.user/webServer.password in frpc.toml and pass the same values when constructing the client.
  3. Upgrade the SDK client and frpc to the same release so endpoint paths and auth behavior agree.

Example fix

// before
client := client.New("127.0.0.1:7400") // no auth → 401

// after
client := client.New("127.0.0.1:7400")
client.SetAuth("admin", "strong-password") // must equal webServer.user / webServer.password
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := client.GetAllProxyStatus(ctx); err != nil {
    if m := regexp.MustCompile(`api status code \[(\d+)\]`).FindStringSubmatch(err.Error()); m != nil {
        switch m[1] {
        case "401": // fix webServer credentials on the client
        case "404": // wrong address or endpoint missing in this frpc version
        default:   // check frpc logs for server-side failure
        }
    }
    return err
}

Prevention

When it happens

Trigger: 401 when the auth token/user/password does not match frpc webServer credentials; 404 when the path is served by a different service or an older frpc without that endpoint; 500 when frpc fails internally (e.g. reload with invalid config).

Common situations: SDK client created without or with the wrong auth credentials vs webServer.user/password in frpc.toml; querying a newer API endpoint against an older frpc; strict-mode reload rejecting the config and surfacing as 500.

Related errors


AI-assisted analysis of fatedier/frp@6c8a8d0a97 (2026-08-15). Data as JSON: /api/errors/cfe76581646f6b0c. Report an issue: GitHub.