Add file content type support for PDF and document uploads#121
Open
bledden wants to merge 2 commits intoOpenRouterTeam:mainfrom
Open
Add file content type support for PDF and document uploads#121bledden wants to merge 2 commits intoOpenRouterTeam:mainfrom
bledden wants to merge 2 commits intoOpenRouterTeam:mainfrom
Conversation
The SDK was rejecting file content items with a Zod validation error before requests ever reached the OpenRouter API. This happened because the ChatMessageContentItem union type didn't include a "file" variant, even though the API accepts it. This change adds: - ChatMessageContentItemFile schema to the OpenAPI spec - New TypeScript types and Zod schemas for file content - Export from the models index - E2E test confirming PDF uploads work correctly The file content type supports: - filename (required) - file_data (URL or base64-encoded content) - file_id (for previously uploaded files) Fixes OpenRouterTeam#83
Author
|
Schema verification: I confirmed the file content type schema against the OpenRouter PDF documentation. The documented format is: {
"type": "file",
"file": {
"filename": "document.pdf",
"file_data": "https://example.com/document.pdf"
}
}The implementation matches this exactly. I also included an optional |
The TypeScript SDK repo does not accept direct changes to generated code. Only the OpenAPI spec change and E2E test should be included. The maintainers will regenerate the SDK after merging. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
What is preventing this from being reviewed and merged? |
|
I'm blocked by this as well - need to send PDFs through the OpenRouter Typescript SDK. Is there a timeline for merging this in? |
Contributor
|
@kuang this should already be fixed can you try it on the latest version of the SDK? |
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
This PR fixes an issue where the SDK rejects file content items (
type: 'file') with a Zod validation error before requests ever reach the OpenRouter API. Users couldn't send PDFs or other documents using the documented format.The problem: The
ChatMessageContentItemtype only included text, image, audio, and video variants. When users tried to send file content as documented, the SDK's internal validation failed immediately.The fix: Added the missing
ChatMessageContentItemFiletype that matches what the OpenRouter API actually accepts.Changes
ChatMessageContentItemFileschema to the OpenAPI specChatMessageContentItemunion to include the file variantTesting
The fix was validated by:
type: "file"is acceptedExample usage
Fixes #83