Repository navigation
Description
Summary
Six constructs do not survive conversion, and they share two causes: the provider request types have no field for tools, and the Gemini part type can only hold text.
| # | route | caller sent | forwarded |
|---|---|---|---|
| 1 | OpenAI to Anthropic | tools and named tool_choice |
{"role":"user","content":"..."} only |
| 2 | OpenAI to Gemini | tools and named tool_choice |
{"role":"user","parts":[{"text":"..."}]} only |
| 3 | OpenAI to Gemini | image_url with a data URL |
the whole content array serialised into a text part |
| 4 | OpenAI to Gemini | role: tool message |
promoted to role: user with the text |
| 5 | Anthropic to OpenAI | image block |
the Anthropic block forwarded unchanged |
| 6 | OpenAI to Anthropic | image_url part |
the OpenAI part forwarded unchanged |
Case 3 is the most visible. The content array is stringified and sent as prose:
"parts": [{"text": "[{\"image_url\":{\"url\":\"data:image/png;base64,iVBOR...\"},\"type\":\"image_url\"}]"}]The model receives a JSON string describing an image instead of an image.
Cases 1 and 2 have the same cause. Neither provider request type has a tools field:
struct GeminiRequest {
contents: Vec<GeminiContent>,
system_instruction: Option<GeminiContent>,
generation_config: Option<GeminiGenerationConfig>,
}crates/tw-provider/src/providers/google.rs:29. AnthropicRequest in crates/tw-provider/src/providers/anthropic.rs likewise has no tools or tool_choice member.
The OpenAI top-level fields do survive deserialization in ChatCompletionRequest.extra, so the values reach the converter and have nowhere to go.
Case 3 and 4 follow from the part type. crates/tw-provider/src/providers/google.rs:45:
struct GeminiPart {
#[serde(skip_serializing_if = "Option::is_none")]
text: Option<String>,
}A part can only hold text, and convert_request at line 83 makes the consequence explicit:
let text = match &msg.content {
serde_json::Value::String(s) => s.clone(),
other => other.to_string(),
};Any content that is not a plain string takes the other arm, and to_string() on a serde_json::Value produces its JSON text. That is the stringification in case 3. The same absence of a non-text part is why a role: tool message becomes a user turn in case 4.
Cases 5 and 6, the converters copy msg.content across without mapping carriers, so an Anthropic image block reaches an OpenAI upstream in Anthropic shape and the reverse.
Reproduction
# case 1
curl -X POST http://<gateway>/v1/chat/completions \
-H 'content-type: application/json' -H "authorization: Bearer $KEY" \
-d '{"model":"<anthropic-model>","messages":[{"role":"user","content":"Use the submit tool."}],
"tool_choice":{"type":"function","function":{"name":"submit"}},
"tools":[{"type":"function","function":{"name":"submit","description":"t",
"parameters":{"type":"object","properties":{}}}}]}'
# case 3
curl -X POST http://<gateway>/v1/chat/completions \
-H 'content-type: application/json' -H "authorization: Bearer $KEY" \
-d '{"model":"<gemini-model>","messages":[{"role":"user","content":[
{"type":"image_url","image_url":{"url":"data:image/png;base64,iVBORw0KGgo="}}]}]}'Then read the request sent upstream.
Expected
Cases 1 and 2, add tools and tool_choice to the provider request types and map them. Both targets define tool calling, so the values have a destination.
Case 3, GeminiPart needs an inline_data variant so an image can be carried as bytes rather than serialised into prose. Stringifying the content array is worse than dropping it, because the model treats the JSON as user text.
Case 4, a role: tool message maps onto a Gemini functionResponse part.
Cases 5 and 6, the content carriers need translating rather than copying. An Anthropic image block and an OpenAI image_url part are not interchangeable on the wire.
Version
ThinkWatch-Core 20e5b6b, reached from ThinkWatch 7a6a93d.
Activity
fylorn commentedon Sep 23, 2026
Fixed by removing the provider conversion layer rather than patching it.
dev): a request whose route speaks the caller's format is forwarded as sent, with only the model name and PII placeholders changed. A request that has to cross formats goes throughtw-dialect, which carries tools,tool_choiceand non-text content across all five formats. An integration test now checks that an Anthropic request with its system array, tools,tool_choice,metadataandcache_controlreaches the upstream byte-for-byte.tw-providerandtw-protocolare deleted. What the server edition still needed from them for Bedrock (eventstream unframing, usage names) now lives intw-upstreamandtw-wire.Android-Login-Analysis commentedon Sep 24, 2026
@fylorn Thanks for the quick fix. I rechecked against
tw-dialectin ThinkWatch-Core v0.43.0 (caec54c), the version ThinkWatchff167b3pins. Tools,tool_choice, images and PDFs now cross formats. Four inputs from the original cases are still lost.1. OpenAI
filepart with onlyfile_idOpenAI to Anthropic and OpenAI to Gemini. The Chat decoder keeps a
filepart only when it hasfile_data(crates/tw-dialect/src/chat/request.rs:214).2. OpenAI
input_audiopartOpenAI to Anthropic and OpenAI to Gemini.
user_partshas no case forinput_audio, so the part is dropped (crates/tw-dialect/src/chat/request.rs:219). Gemini accepts audio asinlineData.3. Anthropic
container_uploadblockAnthropic to OpenAI and Anthropic to Gemini. The Anthropic decoder has no case for
container_upload, so itsfile_idis not carried (crates/tw-dialect/src/anthropic/request.rs:186).4. Tool
stricton the Gemini targetAnthropic to Gemini and OpenAI to Gemini. The Gemini encoder keeps only the schema (
crates/tw-dialect/src/gemini/request.rs:385). The Chat and Anthropic encoders keepstrict. Unlike 1 to 3, this one is not added to the drop list.Please correct me from wrong if I missed anything. Thanks again