Fix Copilot codex model Responses API translation for Claude Code#233
Conversation
ultraplan-bit
commented
Feb 15, 2026
- Add response.function_call_arguments.delta handler for tool call parameters
- Rewrite normalizeGitHubCopilotResponsesInput to produce structured input array (message/function_call/function_call_output) instead of flattened text, fixing infinite loop in multi-turn tool-use conversations
- Skip flattenAssistantContent for messages containing tool_use blocks, preventing function_call items from being destroyed
- Add reasoning/thinking stream & non-stream support
- Fix stop_reason mapping (max_tokens/stop) and cached token reporting
- Update test to match new array-based input format
- Add response.function_call_arguments.delta handler for tool call parameters - Rewrite normalizeGitHubCopilotResponsesInput to produce structured input array (message/function_call/function_call_output) instead of flattened text, fixing infinite loop in multi-turn tool-use conversations - Skip flattenAssistantContent for messages containing tool_use blocks, preventing function_call items from being destroyed - Add reasoning/thinking stream & non-stream support - Fix stop_reason mapping (max_tokens/stop) and cached token reporting - Update test to match new array-based input format Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @ultraplan-bit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the translation layer for Copilot Codex model responses to the Claude API, focusing on improving the fidelity and functionality of complex conversational interactions. The changes ensure that multi-turn tool-use scenarios are handled robustly, reasoning processes are accurately conveyed, and token usage is reported with greater precision, leading to a more reliable and feature-rich integration. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request significantly improves the translation of GitHub Copilot Codex Responses API for Claude Code. It addresses a critical issue where multi-turn tool-use conversations would fail due to flattened input text, by implementing a structured input array that preserves conversation history (roles, tool calls, and results). Additionally, it adds support for reasoning/thinking blocks in both streaming and non-streaming modes, fixes token reporting for cached tokens, and improves stop reason mapping. My feedback focuses on ensuring the structured input for images follows the expected API schema and refining the stop reason mapping for full Claude compatibility.
| part := `{"type":"input_image","image_url":""}` | ||
| part, _ = sjson.Set(part, "image_url", fmt.Sprintf("data:%s;base64,%s", mediaType, data)) |
There was a problem hiding this comment.
The structure for input_image in the OpenAI Responses API (which Copilot Codex follows) expects image_url to be an object containing a url field, rather than a direct string. Providing it as a string may cause the upstream API to reject the request.
part := `{"type":"input_image","image_url":{"url":""}}`\n part, _ = sjson.Set(part, "image_url.url", fmt.Sprintf("data:%s;base64,%s", mediaType, data))| } else if sr := root.Get("stop_reason").String(); sr == "max_tokens" || sr == "stop" { | ||
| out, _ = sjson.Set(out, "stop_reason", sr) |
There was a problem hiding this comment.
For Claude-compatible responses, the stop_reason should be mapped to Claude's expected enum values. While max_tokens is valid, OpenAI's stop should be mapped to Claude's end_turn to ensure clients (like Claude Code) correctly interpret the completion.
} else if sr := root.Get("stop_reason").String(); sr == "max_tokens" || sr == "stop" {\n if sr == "stop" { sr = "end_turn" }\n out, _ = sjson.Set(out, "stop_reason", sr)| } else if sr := gjson.GetBytes(payload, "response.stop_reason").String(); sr == "max_tokens" || sr == "stop" { | ||
| stopReason = sr |
There was a problem hiding this comment.
Similar to the non-streaming case, the stop reason from the upstream API should be mapped to end_turn for Claude compatibility in the streaming response.
} else if sr := gjson.GetBytes(payload, "response.stop_reason").String(); sr == "max_tokens" || sr == "stop" {\n if sr == "stop" { stopReason = "end_turn" } else { stopReason = sr }