{"record":{"id":"2971202e7fb06217","repo":"github/copilot-sdk","slug":"failed-to-set-model-w","errorCode":null,"errorMessage":"failed to set model: %w","messagePattern":"failed to set model: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/session.go","lineNumber":2006,"sourceCode":"\t\tparams.ReasoningSummary = opts.ReasoningSummary\n\t\tparams.ContextTier = opts.ContextTier\n\t\tparams.ModelCapabilities = opts.ModelCapabilities\n\n\t\t// The generated field is a double pointer so the three cases stay\n\t\t// distinct on the wire: a nil outer pointer omits the field and leaves\n\t\t// any staged preference alone, while a non-nil outer pointer sends the\n\t\t// inner value, including an explicit null.\n\t\tswitch {\n\t\tcase opts.AutoTier != nil:\n\t\t\tparams.AutoTier = &opts.AutoTier\n\t\tcase opts.ResetAutoTier:\n\t\t\tvar providerDefault *AutoTier\n\t\t\tparams.AutoTier = &providerDefault\n\t\t}\n\t}\n\t_, err := s.RPC.Model.SwitchTo(ctx, params)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set model: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// SetAutoTier changes the Auto routing preference without changing the selected model.\n//\n// The runtime does not apply the preference immediately. It records the request and\n// commits it only when a later user turn using the \"auto\" model successfully obtains a\n// usable model from the provider. A [rpc.ModelSwitchAutoTierStatusPending] status\n// therefore confirms that the request was accepted, not that it took effect.\n//\n// Watch for the outcome through the session.model_change event on success, or the\n// ephemeral session.auto_tier_switch_failed event on failure. You can also read the\n// current committed and in-flight state at any time with session.RPC.Model.GetCurrent.\n//\n// Only the most recent request survives: issuing a new request replaces any earlier one\n// that has not yet been claimed by a turn.","sourceCodeStart":1988,"sourceCodeEnd":2024,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/session.go#L1988-L2024","documentation":"Session's model-switch path (SetModel) builds switch parameters (model, optional provider, auto-tier defaults) and calls s.RPC.Model.SwitchTo. This error wraps any failure of that RPC — unknown model/provider identifier, invalid auto-tier combination, or transport failure.","triggerScenarios":"Calling SetModel (or the session model API) with a model/provider identifier the runtime rejects, an unsupported AutoTier value for that provider, or when the RPC transport fails.","commonSituations":"Typo'd model ID; referencing a model removed in a newer runtime; passing a provider that doesn't serve the requested model; setting AutoTier on a provider without tier support.","solutions":["Verify the model ID/provider string against the runtime's model list","Check that the AutoTier value is valid for the chosen provider","Inspect the wrapped error for the runtime's specific rejection reason","Upgrade SDK/runtime together if the model was added in a newer release"],"exampleFix":"// before\nerr := session.SetModel(ctx, \"gpt-5-turbo\", \"\")\n// after\nif err := session.SetModel(ctx, \"gpt-5-turbo\", \"\"); err != nil {\n    log.Printf(\"set model failed: %v — check model/provider IDs\", err)\n}","handlingStrategy":"validation","validationCode":"var validModels = map[string]bool{\"claude-sonnet-4\": true /* ...from runtime list */}\nif !validModels[modelID] {\n    return fmt.Errorf(\"unknown model %q\", modelID)\n}","typeGuard":null,"tryCatchPattern":"if err := session.SetModel(ctx, model, provider); err != nil {\n    log.Printf(\"set model failed: %v\", err)\n    return fmt.Errorf(\"model %q/provider %q rejected: %w\", model, provider, err)\n}","preventionTips":["Validate model/provider IDs against the runtime's advertised list","Only pass AutoTier when the provider supports it","Upgrade SDK and runtime together when new models ship"],"tags":["go","model","rpc","configuration"],"backgroundTag":"api-request-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}