Skip to content

fix(openai): omit filename for URL-backed PDFs in Responses API requests#2166

Open
dgrijalva wants to merge 1 commit into
0xPlaygrounds:mainfrom
dgrijalva:fix/openai-responses-url-pdf-filename
Open

fix(openai): omit filename for URL-backed PDFs in Responses API requests#2166
dgrijalva wants to merge 1 commit into
0xPlaygrounds:mainfrom
dgrijalva:fix/openai-responses-url-pdf-filename

Conversation

@dgrijalva

Copy link
Copy Markdown
Contributor

Fixes #2164

Problem

Two conversions in responses_api/mod.rs produce input_file content parts. #1432 (closing #1429) fixed TryFrom<message::Message> for Vec<Message>, but requests built by CompletionModel::completion() go through TryFrom<crate::completion::Message> for Vec<InputItem>, whose PDF arm still set filename: Some("document.pdf") unconditionally — including alongside file_url, which the API rejects with 400 mutually_exclusive_parameters (file inputs docs).

Implementation

filename is now produced by the same match as file_data/file_url: Some("document.pdf") for base64 documents, None for URLs — mirroring what #1432 did in the parallel conversion. No public API changes.

Testing

  • Unit tests pin the serialized input_file JSON for URL PDFs on all three paths (Vec<InputItem>, the full wire request via TryFrom<(String, CompletionRequest)>, and Vec<Message>), plus base64 PDFs keeping their filename.
  • New cassette test url_pdf_document_prompt recorded against the live API (recording fails with the 400 before this fix); full OpenAI cassette suite replays green.
  • cargo clippy --all-features --all-targets and cargo fmt -- --check clean.

Related: #1429, #1432

The PDF arm of TryFrom<crate::completion::Message> for Vec<InputItem>
set filename: Some("document.pdf") unconditionally, so URL-backed PDFs
were serialized with both file_url and filename — a combination the
Responses API rejects with 400 mutually_exclusive_parameters. PR 0xPlaygrounds#1432
fixed the same bug in the parallel TryFrom<message::Message> for
Vec<Message> conversion, but not on this path, which is the one
CompletionModel::completion() requests are built through.

filename now comes from the same match as file_data/file_url:
Some("document.pdf") for base64 documents, None for URLs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: URL-backed PDFs still get 400 mutually_exclusive_parameters from the OpenAI Responses API

1 participant