CLIProxyAPI icon indicating copy to clipboard operation
CLIProxyAPI copied to clipboard

[Bug] `/v1/responses` -> Claude sets `application/octet-stream` on raw-base64 `input_file` PDFs (ignoring `.pdf` filename) and stringifies non-array `function_call_output` media

Open BodaFu opened this issue 2 weeks ago • 0 comments

Is it a request payload issue? [x] Yes, this is a request payload issue. I am using a client/cURL to send a request payload, but I received an unexpected error. [ ] No, it's another issue.

Describe the bug In the OpenAI Responses -> Claude translator (internal/translator/claude/openai/responses/claude_openai-responses_request.go) on main (7df56074), there are two native multimodal translation bugs:

  1. Raw-base64 input_file ignores filename: "*.pdf" and emits media_type: "application/octet-stream" (lines 447-464 and 1619-1638):
    • OpenAI Responses clients allow input_file with either a data:application/pdf;base64,... URI or raw base64 file_data + "filename": "report.pdf" (which CLIProxyAPI's Gemini/Codex translators accept via NormalizeOpenAIFileData + filename fallback).
    • However, claude_openai-responses_request.go hardcodes mediaType := "application/octet-stream" whenever fileData does not start with data:, ignoring part.Get("filename") and PDF %PDF- (JVBERi0) magic prefixes. Anthropic /v1/messages rejects document blocks with media_type: "application/octet-stream" with HTTP 400.
  2. Non-array object function_call_output.output and unsupported media parts (lines 1231-1272):
    • applyResponsesToolResultContentDoc checks only output.IsArray(). If function_call_output.output is a single media object (which gemini_openai-responses_request.go:1749-1778 supports), it falls through to toolResultDoc.Set("content", output.String()), dumping raw base64 JSON as plain text.
    • Similarly, in openai_openai-responses_request.go:655-675, 690-736 (Responses -> OpenAI Chat), input_file inside function_call_output.output falls back to raw JSON text instead of native file relay or explicit error.

CLI Type claude code (via /v1/responses OpenAI Responses translator)

Model Name claude-sonnet-4-6, claude-opus-4-6

LLM Client OpenAI SDK (client.responses.create) / cURL

Request Information

curl http://127.0.0.1:8317/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-sonnet-4-6",
    "input": [
      {
        "role": "user",
        "content": [
          {
            "type": "input_text",
            "text": "What two words are inside this PDF?"
          },
          {
            "type": "input_file",
            "filename": "sample.pdf",
            "file_data": "JVBERi0xLjQKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0NvdW50IDEvS2lkc1szIDAgUl0+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9NZWRpYUJveFswIDAgMjAwIDIwMF0vQ29udGVudHMgNCAwIFIvUmVzb3VyY2VzPDwvRm9udDw8L0YxIDUgMCBSPj4+Pj4+ZW5kb2JqCjQgMCBvYmo8PC9MZW5ndGggNDQ+PnN0cmVhbQpCVCAvRjEgMTggVGYgMjAgMTAwIFRkIChIZWxsbyBQREYpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iajw8L1R5cGUvRm9udC9TdWJ0eXBlL1R5cGUxL0Jhc2VGb250L0hlbHZldGljYT4+ZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDUyIDAwMDAwIG4gCjAwMDAwMDAxMDEgMDAwMDAgbiAKMDAwMDAwMDIxMiAwMDAwMCBuIAowMDAwMDAwMzA1IDAwMDAwIG4gCnRyYWlsZXI8PC9TaXplIDYvUm9vdCAxIDAgUj4+CnN0YXJ0eHJlZgozNzUKJSVFT0YK"
          }
        ]
      }
    ]
  }'

Expected behavior

  1. Infer application/pdf from filename extension (.pdf) or %PDF- base64 prefix (JVBERi0) when file_data is raw base64, and handle file_url -> Claude URL document source ({"type": "url", "url": ...}).
  2. Support single-object function_call_output.output consistently with array output, and reject unsupported binary modalities rather than dumping base64 as text.

OS Type

  • OS: Linux (x86_64) / macOS

BodaFu avatar Nov 17 '26 03:11 BodaFu