{"record":{"id":"a638ff4b3d95e0e5","repo":"wavetermdev/waveterm","slug":"unsupported-api-type-s","errorCode":null,"errorMessage":"unsupported API type: %s","messagePattern":"unsupported API type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/usechat-backend.go","lineNumber":76,"sourceCode":"// Compile-time interface checks\nvar _ UseChatBackend = (*openaiResponsesBackend)(nil)\nvar _ UseChatBackend = (*openaiCompletionsBackend)(nil)\nvar _ UseChatBackend = (*anthropicBackend)(nil)\nvar _ UseChatBackend = (*geminiBackend)(nil)\n\n// GetBackendByAPIType returns the appropriate UseChatBackend implementation for the given API type\nfunc GetBackendByAPIType(apiType string) (UseChatBackend, error) {\n\tswitch apiType {\n\tcase uctypes.APIType_OpenAIResponses:\n\t\treturn &openaiResponsesBackend{}, nil\n\tcase uctypes.APIType_OpenAIChat:\n\t\treturn &openaiCompletionsBackend{}, nil\n\tcase uctypes.APIType_AnthropicMessages:\n\t\treturn &anthropicBackend{}, nil\n\tcase uctypes.APIType_GoogleGemini:\n\t\treturn &geminiBackend{}, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported API type: %s\", apiType)\n\t}\n}\n\n// openaiResponsesBackend implements UseChatBackend for OpenAI API\ntype openaiResponsesBackend struct{}\n\nfunc (b *openaiResponsesBackend) RunChatStep(\n\tctx context.Context,\n\tsseHandler *sse.SSEHandlerCh,\n\tchatOpts uctypes.WaveChatOpts,\n\tcont *uctypes.WaveContinueResponse,\n) (*uctypes.WaveStopReason, []uctypes.GenAIMessage, *uctypes.RateLimitInfo, error) {\n\tstopReason, msgs, rateLimitInfo, err := openai.RunOpenAIChatStep(ctx, sseHandler, chatOpts, cont)\n\tvar genMsgs []uctypes.GenAIMessage\n\tfor _, msg := range msgs {\n\t\tgenMsgs = append(genMsgs, msg)\n\t}\n\treturn stopReason, genMsgs, rateLimitInfo, err","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/usechat-backend.go#L58-L94","documentation":"GetBackendByAPIType maps an API-type string to a UseChatBackend implementation (openai-responses, openai-completions, anthropic-messages, google-gemini). Any other string returns this error because no backend exists for it.","triggerScenarios":"Calling GetBackendByAPIType with a value not among uctypes.APIType_OpenAIResponses, APIType_OpenAIChat, APIType_AnthropicMessages, APIType_GoogleGemini — e.g. an empty APIType, \"openai\", \"gpt-4\", or an arbitrary config string. Raised from callers ConvertAIChatToUIChat, WaveAIPostMessageWrap, and CreateWriteTextFileDiff.","commonSituations":"Config file with a typo'd or legacy apitype value; env var unset yielding empty string; adding a new provider in code but sending the new type before registering a backend case; case mismatch (\"OpenAI\" vs the lowercase constant).","solutions":["Set the API type to one of the supported constants: openai-responses, openai-completions, anthropic-messages, google-gemini (use the uctypes.APIType_* constants)","Check the config/env value for typos, casing, and emptiness before calling","Add a new case in GetBackendByAPIType if you are integrating a new provider backend"],"exampleFix":"// before\nbackend, err := aiusechat.GetBackendByAPIType(apiType) // apiType = \"openai\"\n// after\nbackend, err := aiusechat.GetBackendByAPIType(uctypes.APIType_OpenAIChat) // \"openai-completions\"","handlingStrategy":"validation","validationCode":"func knownAPIType(t string) bool {\n\tswitch t {\n\tcase uctypes.APIType_OpenAIResponses, uctypes.APIType_OpenAIChat,\n\t\tuctypes.APIType_AnthropicMessages, uctypes.APIType_GoogleGemini:\n\t\treturn true\n\t}\n\treturn false\n}","typeGuard":"func resolveBackend(t string) (aiusechat.UseChatBackend, error) {\n\tif !knownAPIType(t) {\n\t\treturn nil, fmt.Errorf(\"apitype %q not configured\", t)\n\t}\n\treturn aiusechat.GetBackendByAPIType(t)\n}","tryCatchPattern":"backend, err := aiusechat.GetBackendByAPIType(cfg.APIType)\nif err != nil {\n\tlog.Printf(\"bad apitype %q: %v; defaulting\", cfg.APIType, err)\n\tbackend, err = aiusechat.GetBackendByAPIType(uctypes.APIType_OpenAIResponses)\n}\nif err != nil { return err }","preventionTips":["Reference uctypes.APIType_* constants instead of literals in config code","Fail at startup if the configured apitype is empty or unknown","When adding a provider, register its case in GetBackendByAPIType before shipping the type string"],"tags":["configuration","backend-selection","ai-providers"],"backgroundTag":"unsupported-provider-type","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}