-
Notifications
You must be signed in to change notification settings - Fork 191
feat(gateway): document support for Gemini AI Studio #2354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
steebchen
merged 19 commits into
theopenco:main
from
RATCHAW:RATCHAW/support-document-attachments
May 28, 2026
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
60df122
feat(gateway): document support for Gemini AI Studio
RATCHAW e5e16b3
Merge branch 'main' into RATCHAW/support-document-attachments
RATCHAW d5c6e5b
feat(playground): persist document uploads
RATCHAW 8ca1691
Merge branch 'main' into RATCHAW/support-document-attachments
RATCHAW 0093a47
fix(gateway): address PR review for document attachments
RATCHAW 6951802
Merge branch 'main' into RATCHAW/support-document-attachments
RATCHAW 2a57d87
fix(playground): render documents on shared chat page
RATCHAW 06e8303
chore(admin): regenerate v1.d.ts for documents field
RATCHAW 859dafc
Merge branch 'main' into RATCHAW/support-document-attachments
RATCHAW 36cfcf3
Merge branch 'main' into RATCHAW/support-document-attachments
RATCHAW 8222142
fix(gateway): accept RFC 2397 params in file_data data URL
RATCHAW ed33ca6
Merge branch 'main' into RATCHAW/support-document-attachments
RATCHAW a311253
fix(gateway): log client_error for typed pre-upstream input errors
RATCHAW 2d8b7e3
docs: add document reading page
RATCHAW 62156a2
docs: add changelog entry for document reading
RATCHAW 34e5743
Merge branch 'main' into RATCHAW/support-document-attachments
RATCHAW b763ba1
Merge branch 'main' into RATCHAW/support-document-attachments
steebchen ddd37d6
Merge branch 'main' into RATCHAW/support-document-attachments
RATCHAW e32dab4
docs: add changelog image for document reading
RATCHAW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| --- | ||
| title: Document Reading | ||
| description: Learn how to send PDFs and other document data to document-capable models. | ||
| icon: FileText | ||
| --- | ||
|
|
||
| import { Callout } from "fumadocs-ui/components/callout"; | ||
|
|
||
| # Document Reading | ||
|
|
||
| LLMGateway supports sending documents (PDFs and other file types) to document-capable models using OpenAI's `file` content block format. The gateway forwards the document to the underlying provider so the model can read and reason over its contents. | ||
|
|
||
| ## Document-Capable Models | ||
|
|
||
| Document input is currently supported on Google Gemini models via Google AI Studio. You can find document-capable models on the [models page with the document filter](https://llmgateway.io/models?filters=1&document=true). | ||
|
|
||
| ## Sending a Document | ||
|
|
||
| Add a `file` content block to a user message. The `file_data` field must be a base64-encoded data URL that includes the document's MIME type. | ||
|
|
||
| ```bash | ||
| curl -X POST "https://api.llmgateway.io/v1/chat/completions" \ | ||
| -H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "model": "gemini-2.5-flash", | ||
| "messages": [ | ||
| { | ||
| "role": "user", | ||
| "content": [ | ||
| { | ||
| "type": "text", | ||
| "text": "Summarize this document." | ||
| }, | ||
| { | ||
| "type": "file", | ||
| "file": { | ||
| "filename": "report.pdf", | ||
| "file_data": "data:application/pdf;base64,JVBERi0xLjQKJ..." | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }' | ||
| ``` | ||
|
|
||
| ### Content Block Fields | ||
|
|
||
| - **`type`**: must be `"file"`. | ||
| - **`file.filename`** _(optional)_: original filename, shown in the playground and forwarded for context. | ||
| - **`file.file_data`**: base64-encoded data URL of the form `data:<mime-type>;base64,<data>`. | ||
|
|
||
| <Callout type="info"> | ||
| The `file.file_id` field (for referencing files uploaded via a provider's | ||
| Files API) is accepted by the schema but not currently supported by the Google | ||
| transform. Use `file_data` with an inline base64 data URL. | ||
| </Callout> | ||
|
|
||
| ## Supported File Types | ||
|
|
||
| The accepted MIME types depend on the target model. Gemini models commonly support: | ||
|
|
||
| - `application/pdf` | ||
| - `text/plain` | ||
| - `text/html` | ||
| - `text/css` | ||
| - `text/javascript` | ||
| - `text/csv` | ||
| - `text/markdown` | ||
| - `text/xml` | ||
|
|
||
| If the upstream provider rejects the MIME type, the gateway surfaces a `400` error including the unsupported MIME type and the provider it was sent to. To use a different file type, encode the file with the matching MIME type in the data URL prefix. | ||
|
|
||
| ## Encoding a File as a Data URL | ||
|
|
||
| Any tool that can produce base64 output works. For example, in a shell: | ||
|
|
||
| ```bash | ||
| DATA=$(base64 -i report.pdf | tr -d '\n') | ||
| echo "data:application/pdf;base64,$DATA" | ||
| ``` | ||
|
|
||
| Or in JavaScript: | ||
|
|
||
| ```javascript | ||
| import { readFileSync } from "node:fs"; | ||
|
|
||
| const buffer = readFileSync("report.pdf"); | ||
| const fileData = `data:application/pdf;base64,${buffer.toString("base64")}`; | ||
| ``` | ||
|
|
||
| Then pass `fileData` as the `file.file_data` value in your request. | ||
|
|
||
| ## Multiple Documents | ||
|
|
||
| You can include multiple `file` blocks in a single message, optionally mixed with text and image content: | ||
|
|
||
| ```bash | ||
| curl -X POST "https://api.llmgateway.io/v1/chat/completions" \ | ||
| -H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "model": "gemini-2.5-pro", | ||
| "messages": [ | ||
| { | ||
| "role": "user", | ||
| "content": [ | ||
| { "type": "text", "text": "Compare these two reports." }, | ||
| { | ||
| "type": "file", | ||
| "file": { | ||
| "filename": "q1.pdf", | ||
| "file_data": "data:application/pdf;base64,JVBERi0x..." | ||
| } | ||
| }, | ||
| { | ||
| "type": "file", | ||
| "file": { | ||
| "filename": "q2.pdf", | ||
| "file_data": "data:application/pdf;base64,JVBERi0x..." | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }' | ||
| ``` | ||
|
|
||
| ## Error Handling | ||
|
|
||
| The gateway returns `400` for the following document-related errors: | ||
|
|
||
| - The selected model does not support document input. | ||
| - The `file` block is missing both `file_data` and `file_id`. | ||
| - `file_data` is not a valid base64 data URL. | ||
| - The upstream provider rejects the document's MIME type for the selected model. |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.