{"record":{"id":"fd93bac425e3f28c","repo":"wavetermdev/waveterm","slug":"api-version-mismatch-chat-has-s-chatopts-has-s-fd93ba","errorCode":null,"errorMessage":"API version mismatch: chat has %s, chatOpts has %s","messagePattern":"API version mismatch: chat has (.+?), chatOpts has (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/openai/openai-backend.go","lineNumber":487,"sourceCode":"\tif sse == nil {\n\t\treturn nil, nil, nil, errors.New(\"sse handler is nil\")\n\t}\n\n\t// Get chat from store\n\tchat := chatstore.DefaultChatStore.Get(chatOpts.ChatId)\n\tif chat == nil {\n\t\treturn nil, nil, nil, fmt.Errorf(\"chat not found: %s\", chatOpts.ChatId)\n\t}\n\n\t// Validate that chatOpts.Config match the chat's stored configuration\n\tif chat.APIType != chatOpts.Config.APIType {\n\t\treturn nil, nil, nil, fmt.Errorf(\"API type mismatch: chat has %s, chatOpts has %s\", chat.APIType, chatOpts.Config.APIType)\n\t}\n\tif !uctypes.AreModelsCompatible(chat.APIType, chat.Model, chatOpts.Config.Model) {\n\t\treturn nil, nil, nil, fmt.Errorf(\"model mismatch: chat has %s, chatOpts has %s\", chat.Model, chatOpts.Config.Model)\n\t}\n\tif chat.APIVersion != chatOpts.Config.APIVersion {\n\t\treturn nil, nil, nil, fmt.Errorf(\"API version mismatch: chat has %s, chatOpts has %s\", chat.APIVersion, chatOpts.Config.APIVersion)\n\t}\n\n\t// Context with timeout if provided.\n\tif chatOpts.Config.TimeoutMs > 0 {\n\t\tvar cancel context.CancelFunc\n\t\tctx, cancel = context.WithTimeout(ctx, time.Duration(chatOpts.Config.TimeoutMs)*time.Millisecond)\n\t\tdefer cancel()\n\t}\n\n\t// Validate continuation if provided\n\tif cont != nil {\n\t\tif !uctypes.AreModelsCompatible(chat.APIType, chatOpts.Config.Model, cont.Model) {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"cannot continue with a different model, model:%q, cont-model:%q\", chatOpts.Config.Model, cont.Model)\n\t\t}\n\t}\n\n\t// Convert GenAIMessages to input objects (OpenAIMessage or OpenAIFunctionCallInput)\n\tvar inputs []any","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/openai/openai-backend.go#L469-L505","documentation":"RunOpenAIChatStep returns \"API version mismatch\" at openai-backend.go:487 when chat.APIVersion differs from chatOpts.Config.APIVersion. APIVersion matters for Azure OpenAI–style deployments where the API version string must stay consistent with the stored chat configuration.","triggerScenarios":"Calling RunOpenAIChatStep with Config.APIVersion that differs from the version recorded on the chat — e.g. bumping the Azure API version in config while continuing an existing chat, or defaulting APIVersion to empty vs the stored value.","commonSituations":"Upgrading the azure-openai api-version in settings; one client process on a newer version continuing a chat created by an older process; leaving Config.APIVersion unset (\"\") for chats created with an explicit version.","solutions":["Copy chat.APIVersion into chatOpts.Config.APIVersion before the call","Start a new chat after intentionally changing API version","Ensure all clients/servers use the same configured API version for a given chat","For non-Azure (openai) types, set APIVersion consistently (usually empty) rather than partially filling it"],"exampleFix":"// before\nchatOpts.Config.APIVersion = \"2024-10-21\" // newer than chat's stored version\nRunOpenAIChatStep(ctx, sse, chatOpts, nil)\n// after\nchat := chatstore.DefaultChatStore.Get(chatOpts.ChatId)\nchatOpts.Config.APIVersion = chat.APIVersion\nRunOpenAIChatStep(ctx, sse, chatOpts, nil)","handlingStrategy":"validation","validationCode":"chat := chatstore.DefaultChatStore.Get(chatOpts.ChatId)\nif chat != nil && chat.APIVersion != chatOpts.Config.APIVersion {\n    chatOpts.Config.APIVersion = chat.APIVersion\n}","typeGuard":"func apiVersionMatches(chatOpts uctypes.WaveChatOpts) bool {\n    chat := chatstore.DefaultChatStore.Get(chatOpts.ChatId)\n    return chat != nil && chat.APIVersion == chatOpts.Config.APIVersion\n}","tryCatchPattern":"if _, _, _, err := RunOpenAIChatStep(ctx, sse, chatOpts, nil); err != nil {\n    if strings.HasPrefix(err.Error(), \"API version mismatch\") {\n        // sync version from stored chat or start a new chat\n        return nil\n    }\n    return err\n}","preventionTips":["Keep one API version per deployment and apply it to new chats only","Copy APIVersion from the stored chat for continuation calls","Don't leave Config.APIVersion partially populated (empty vs explicit)","Coordinate version bumps across all client/server processes"],"tags":["go","api-version","azure","configuration"],"backgroundTag":"api-version-mismatch","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}