charmbracelet/crush · error
failed to import copilot: status code %d
Error message
failed to import copilot: status code %d
What it means
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.
Source
Thrown at internal/client/config.go:136
return fmt.Errorf("failed to set provider API key: %w", err)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to set provider API key: status code %d", rsp.StatusCode)
}
return nil
}
// ImportCopilot attempts to import a GitHub Copilot token on the
// server.
func (c *Client) ImportCopilot(ctx context.Context, id string) (*oauth.Token, bool, error) {
rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/config/import-copilot", id), nil, nil, nil)
if err != nil {
return nil, false, fmt.Errorf("failed to import copilot: %w", err)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return nil, false, fmt.Errorf("failed to import copilot: status code %d", rsp.StatusCode)
}
var result struct {
Token *oauth.Token `json:"token"`
Success bool `json:"success"`
}
if err := json.NewDecoder(rsp.Body).Decode(&result); err != nil {
return nil, false, fmt.Errorf("failed to decode import copilot response: %w", err)
}
return result.Token, result.Success, nil
}
// RefreshOAuthToken refreshes an OAuth token for a provider on the
// server.
func (c *Client) RefreshOAuthToken(ctx context.Context, id string, scope config.Scope, providerID string) error {
rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/config/refresh-oauth", id), nil, jsonBody(struct {
Scope config.Scope `json:"scope"`
ProviderID string `json:"provider_id"`
}{Scope: scope, ProviderID: providerID}), http.Header{"Content-Type": []string{"application/json"}})View on GitHub (pinned to 7944b8e522)
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
Defensive patterns
Strategy: fallback
Try / catch
tok, ok, err := c.ImportCopilot(ctx, wsID)
if err != nil {
if strings.Contains(err.Error(), "status code 4") {
// fall back to prompting the user for a manual token
return promptForCopilotToken(ctx)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: User has never authenticated with Copilot on the host, credentials expired, workspace id wrong, or server build predates the endpoint.
Related errors
- failed to import copilot: %w
- device code request failed: %s - %s
- copilot token request failed: %s - %s
- could not create request: %w
- unexpected status code: %d
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/6bcd9d3593d3feea.
Report an issue: GitHub.