fix(provider): Fix OpenAI compatible tool result message format#2
Merged
Conversation
Fix ToolResultBlock conversion to OpenAI format for OpenRouter/Anthropic compatibility. Changes: - Convert ToolResultBlock to independent role:"tool" messages (OpenAI API spec) - Extract ToolUseBlock from ContentBlocks for assistant messages - Ensure assistant messages with tool_calls have content field Add OpenRouter demo with verification tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
lwmacct
had a problem deploying
to
github-pages
November 26, 2025 18:37 — with
GitHub Actions
Failure
Contributor
|
不要新增demo 目录,在examples 目录实现 |
- Move demo/1000.openrouter/ → examples/openrouter/ - Remove demo/ directory to maintain consistent project structure - Update providers README with reference to complete example - Keep core OpenAI compatible provider fix unchanged 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
感谢你的贡献!🎉 审核结果✅ 核心修复代码
📁 目录结构调整为了保持项目一致性,我对目录结构做了小幅调整:
✅ 验证通过
如果你同意这些调整,我可以直接合并这个 PR。再次感谢你的优质贡献!💯 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix ToolResultBlock conversion to OpenAI format for OpenRouter/Anthropic compatibility.
Problem: When using OpenRouter to access Anthropic models, tool call results were not being properly formatted, causing 403 "Request not allowed" errors on subsequent API calls.
Root Cause: The
OpenAICompatibleProvider.convertMessages()function was not correctly handling:ToolResultBlock- needs to be converted to independentrole: "tool"messagesToolUseBlockin ContentBlocks - needs to be extracted for assistant messagesChanges:
ToolResultBlockto independentrole: "tool"messages (OpenAI API spec)ToolUseBlockfromContentBlocksfor assistant messagestool_callshave acontentfield (required by OpenRouter → Anthropic)Test Results
Added OpenRouter demo with verification tests:
Tested Models:
anthropic/claude-sonnet-4.5via OpenRouter ✅anthropic/claude-haiku-4.5via OpenRouter ✅Test Plan
go run demo/1000.openrouter/main.gowith validOPENROUTER_API_KEY🤖 Generated with Claude Code