{"record":{"id":"6bcd9d3593d3feea","repo":"charmbracelet/crush","slug":"failed-to-import-copilot-status-code-d","errorCode":null,"errorMessage":"failed to import copilot: status code %d","messagePattern":"failed to import copilot: status code (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":136,"sourceCode":"\t\treturn fmt.Errorf(\"failed to set provider API key: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to set provider API key: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// ImportCopilot attempts to import a GitHub Copilot token on the\n// server.\nfunc (c *Client) ImportCopilot(ctx context.Context, id string) (*oauth.Token, bool, error) {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/import-copilot\", id), nil, nil, nil)\n\tif err != nil {\n\t\treturn nil, false, fmt.Errorf(\"failed to import copilot: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, false, fmt.Errorf(\"failed to import copilot: status code %d\", rsp.StatusCode)\n\t}\n\tvar result struct {\n\t\tToken   *oauth.Token `json:\"token\"`\n\t\tSuccess bool         `json:\"success\"`\n\t}\n\tif err := json.NewDecoder(rsp.Body).Decode(&result); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"failed to decode import copilot response: %w\", err)\n\t}\n\treturn result.Token, result.Success, nil\n}\n\n// RefreshOAuthToken refreshes an OAuth token for a provider on the\n// server.\nfunc (c *Client) RefreshOAuthToken(ctx context.Context, id string, scope config.Scope, providerID string) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/refresh-oauth\", id), nil, jsonBody(struct {\n\t\tScope      config.Scope `json:\"scope\"`\n\t\tProviderID string       `json:\"provider_id\"`\n\t}{Scope: scope, ProviderID: providerID}), http.Header{\"Content-Type\": []string{\"application/json\"}})","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L118-L154","documentation":"ImportCopilot requires HTTP 200. A non-200 response (no Copilot credentials available server-side, auth failure, missing workspace) is returned as this error with the status code.","triggerScenarios":"Server responds non-200 to the import-copilot request — commonly when no Copilot token exists on the machine/server, or auth to the server fails.","commonSituations":"User has never authenticated with Copilot on the host, credentials expired, workspace id wrong, or server build predates the endpoint.","solutions":["Check the status code: 401/403 means re-authenticate with the server","For 404, verify workspace id and server version support","Ensure Copilot credentials exist on the machine (e.g. gh CLI auth) before importing","Fall back to manual token entry if import is unavailable"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"tok, ok, err := c.ImportCopilot(ctx, wsID)\nif err != nil {\n    if strings.Contains(err.Error(), \"status code 4\") {\n        // fall back to prompting the user for a manual token\n        return promptForCopilotToken(ctx)\n    }\n    return err\n}","preventionTips":["Verify Copilot credentials exist on the machine before attempting import","Handle 401 by re-authenticating with the server first","Provide a manual token entry path when import is unsupported"],"tags":["http","copilot","auth"],"backgroundTag":"http-non-200-response","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}