-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: normalize tool call IDs for cross-provider compatibility via OpenRouter #10102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Review complete. No issues found. The latest commit correctly moves Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Some providers (like Mistral) require tool call IDs to be: - Only alphanumeric characters (a-z, A-Z, 0-9) - Exactly 9 characters in length This caused errors when conversations with tool calls from one provider (e.g., OpenAI's call_xxx format) were routed to Mistral via OpenRouter. Solution: - Added normalizeToolCallId() function that strips non-alphanumeric characters and pads/truncates to exactly 9 characters - Added modelId option to convertToOpenAiMessages() that conditionally normalizes IDs only when the model contains 'mistral' - OpenRouter now passes modelId to enable normalization for Mistral models - Direct Mistral provider uses convertToMistralMessages() which always normalizes IDs This scoped approach only affects Mistral models, avoiding any potential impact on the 15+ other providers using OpenAI-compatible format. Example transformations: - call_5019f900a247472bacde0b82 → call5019f - toolu_01234567890abcdef → toolu0123 - weather-123 → weather12
87e8348 to
72eddd7
Compare
cte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one nitpick.
…OpenAiMessages Addresses PR feedback about separation of concerns. The convertToOpenAiMessages function now accepts an optional normalizeToolCallId function instead of checking for 'mistral' in the modelId. This allows callers to flexibly declare the tool call ID format without the transform module needing to know about provider-specific requirements.
Moves the tool call ID normalization function to mistral-format.ts with explicit Mistral naming (normalizeMistralToolCallId) since Mistral is the only provider that requires this specific 9-character alphanumeric ID format. This better separates concerns by keeping provider-specific logic in the appropriate module while keeping the generic convertToOpenAiMessages function flexible via the optional normalizeToolCallId callback.
|
Very nice! |
Summary
Some providers (like Mistral) require tool call IDs to be:
This caused errors when conversations with tool calls from one provider (e.g., OpenAI's
call_xxxformat) were routed to Mistral via OpenRouter.Error Example
Solution
normalizeToolCallId()function that strips non-alphanumeric characters and pads/truncates to exactly 9 charactersmodelIdoption toconvertToOpenAiMessages()that conditionally normalizes IDs only when the model contains 'mistral'convertToMistralMessages()which always normalizes IDsThis scoped approach only affects Mistral models, avoiding any potential impact on the 15+ other providers using OpenAI-compatible format.
Example Transformations
call_5019f900a247472bacde0b82→call5019ftoolu_01234567890abcdef→toolu0123weather-123→weather12Testing
Important
Adds tool call ID normalization for Mistral models in OpenRouter to ensure compatibility with strict ID requirements.
normalizeMistralToolCallId()inmistral-format.tsto ensure tool call IDs are alphanumeric and 9 characters long.convertToOpenAiMessages()inopenai-format.tsto optionally usenormalizeToolCallIdfor Mistral models.OpenRouterHandlerinopenrouter.tsto pass normalization function for Mistral models.normalizeMistralToolCallId()inmistral-format.spec.ts.openai-format.spec.tsto cover normalization scenarios.This description was created by
for 58410fe. You can customize this summary. It will automatically update as commits are pushed.