{"record":{"id":"3d37de9e4516abc0","repo":"github/copilot-sdk","slug":"githubtoken-and-githubtokenprovider-cannot-be-used-3d37de","errorCode":null,"errorMessage":"GitHubToken and GitHubTokenProvider cannot be used together","messagePattern":"GitHubToken and GitHubTokenProvider cannot be used together","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":839,"sourceCode":"}\n\nfunc hasManagedSettings(enableManagedSettings *bool, managedSettings *ManagedSettings) bool {\n\treturn (enableManagedSettings != nil && *enableManagedSettings) || managedSettings != nil\n}\n\nfunc validateAskUserVariant(variant AskUserVariant) error {\n\tif variant != \"\" && variant != AskUserVariantLegacy && variant != AskUserVariantElicitation {\n\t\treturn fmt.Errorf(\"invalid AskUserVariant %q: expected %q, %q, or unset\", variant, AskUserVariantLegacy, AskUserVariantElicitation)\n\t}\n\treturn nil\n}\n\nfunc (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Session, error) {\n\tif config == nil {\n\t\tconfig = &SessionConfig{}\n\t}\n\tif config.GitHubToken != \"\" && config.GitHubTokenProvider != nil {\n\t\treturn nil, fmt.Errorf(\"GitHubToken and GitHubTokenProvider cannot be used together\")\n\t}\n\tif err := validateAskUserVariant(config.AskUserVariant); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif err := c.ensureConnected(ctx); err != nil {\n\t\treturn nil, err\n\t}\n\n\tc.applyConfigDefaultsForMode(config)\n\n\tregistrationID := c.registerGitHubTokenProvider(config.GitHubTokenProvider)\n\tregistrationTransferred := false\n\tdefer func() {\n\t\tif !registrationTransferred {\n\t\t\tc.unregisterGitHubTokenProvider(registrationID)\n\t\t}\n\t}()","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L821-L857","documentation":"SessionConfig allows supplying a GitHub token either directly (GitHubToken) or via a provider function (GitHubTokenProvider), but not both. CreateSession rejects the combination explicitly to avoid ambiguity about which credential source wins.","triggerScenarios":"Calling Client.CreateSession with config.GitHubToken non-empty AND config.GitHubTokenProvider non-nil.","commonSituations":"Merging default config with user config where both sources set a token; migrating from static tokens to providers while leaving the old field populated.","solutions":["Remove GitHubToken and keep only GitHubTokenProvider, or vice versa.","Audit config-merging code so only one credential source survives the merge.","Prefer GitHubTokenProvider for dynamic/refreshing credentials."],"exampleFix":"// before\ncfg := &SessionConfig{GitHubToken: \"ghp_...\", GitHubTokenProvider: provider}\n// after\ncfg := &SessionConfig{GitHubTokenProvider: provider}","handlingStrategy":"validation","validationCode":"if cfg.GitHubToken != \"\" && cfg.GitHubTokenProvider != nil { return errors.New(\"set only one of GitHubToken / GitHubTokenProvider\") }","typeGuard":null,"tryCatchPattern":"if _, err := client.CreateSession(ctx, cfg); err != nil && strings.Contains(err.Error(), \"cannot be used together\") { /* fix config */ }","preventionTips":["Centralize SessionConfig construction","Keep one credential source per config","Prefer GitHubTokenProvider for dynamic credentials"],"tags":["go","config","authentication"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}