wavetermdev/waveterm · error
APIType must be '%s', got '%s'
Error message
APIType must be '%s', got '%s'
What it means
ConvertAIChatToUIChat only converts chats whose native format is the Anthropic Messages API. The guard verifies aiChat.APIType equals uctypes.APIType_AnthropicMessages; passing a chat produced by another provider (OpenAI, Google, etc.) is rejected with the expected and actual API types.
Source
Thrown at pkg/aiusechat/anthropic/anthropic-convertmessage.go:817
contentBlocks = append(contentBlocks, anthropicMessageContentBlock{
Type: "tool_result",
ToolUseID: result.ToolUseID,
Content: content,
IsError: isError,
})
}
return &anthropicChatMessage{
MessageId: uuid.New().String(),
Role: "user",
Content: contentBlocks,
}, nil
}
// ConvertAIChatToUIChat converts an AIChat to a UIChat for Anthropic
func ConvertAIChatToUIChat(aiChat uctypes.AIChat) (*uctypes.UIChat, error) {
if aiChat.APIType != uctypes.APIType_AnthropicMessages {
return nil, fmt.Errorf("APIType must be '%s', got '%s'", uctypes.APIType_AnthropicMessages, aiChat.APIType)
}
uiMessages := make([]uctypes.UIMessage, 0, len(aiChat.NativeMessages))
for i, nativeMsg := range aiChat.NativeMessages {
anthropicMsg, ok := nativeMsg.(*anthropicChatMessage)
if !ok {
return nil, fmt.Errorf("message %d: expected *anthropicChatMessage, got %T", i, nativeMsg)
}
uiMsg := anthropicMsg.ConvertToUIMessage()
if uiMsg != nil {
uiMessages = append(uiMessages, *uiMsg)
}
}
return &uctypes.UIChat{
ChatId: aiChat.ChatId,View on GitHub (pinned to a4447c1563)
Solutions
- Ensure the chat was produced by the Anthropic converter and APIType is APIType_AnthropicMessages
- Check APIType before calling and route to the matching provider's ConvertAIChatToUIChat
- Fix the code path that sets APIType when constructing the AIChat
Example fix
// before
uiChat, err := anthropic.ConvertAIChatToUIChat(aiChat) // APIType=openai
// after
if aiChat.APIType == uctypes.APIType_AnthropicMessages {
uiChat, err = anthropic.ConvertAIChatToUIChat(aiChat)
} else {
uiChat, err = openai.ConvertAIChatToUIChat(aiChat)
} Defensive patterns
Strategy: type-guard
Validate before calling
if aiChat.APIType != uctypes.APIType_AnthropicMessages {
return fmt.Errorf("wrong converter for APIType %s", aiChat.APIType)
} Type guard
func isAnthropicChat(c uctypes.AIChat) bool {
return c.APIType == uctypes.APIType_AnthropicMessages
} Try / catch
if !isAnthropicChat(aiChat) {
return nil, fmt.Errorf("route %s chats to their provider converter", aiChat.APIType)
}
uiChat, err := anthropic.ConvertAIChatToUIChat(aiChat) Prevention
- Store APIType alongside cached chats and dispatch converters by it
- Never share one AIChat across provider code paths
- Add a switch on APIType that routes to the matching converter
When it happens
Trigger: Calling ConvertAIChatToUIChat with an AIChat whose APIType field is anything other than APIType_AnthropicMessages — e.g. a chat built by an OpenAI converter.
Common situations: Mixing provider chat objects after refactoring, storing chats in a shared cache without the APIType, or routing the wrong chat to the Anthropic UI converter.
Related errors
- convertFileUIMessagePart expects 'file' type, got '%s'
- unsupported URL protocol in file part: %s
- failed to decode base64 data: %w
- dropping text/plain file with URL (must be fetched and conve
- dropping file with unsupported media type '%s' (must be uplo
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/15d9645b77db6d7c.
Report an issue: GitHub.