Skip to content

Conversation

@jwiegley
Copy link
Contributor

@jwiegley jwiegley commented Oct 4, 2025

Summary

Fixes #929

OpenAI's Vision API only supports image formats (JPEG, PNG, GIF, WebP) and does not support PDFs or other document types. This PR adds MIME type validation to prevent sending unsupported formats through the OpenAI backend.

Changes

  • gptel-openai.el: Added MIME type validation in gptel--openai-parse-multipart function
    • Validates that media files are supported image formats
    • Provides clear error message when unsupported formats (like PDFs) are attempted
    • Guides users to use native Anthropic or Gemini backends for PDF support

Issue Details

When users configured models with PDF support and sent PDFs through OpenRouter's OpenAI-compatible API, the backend would send PDFs as image_url types, causing Azure/OpenAI to reject the request with:

400 Bad Request - Invalid image URL

Solution

The fix validates MIME types before constructing the API request and throws a descriptive error:

(gptel-openai) Request aborted: OpenAI API only supports image formats (JPEG, PNG, GIF, WebP). 
Unsupported MIME type: application/pdf. 
For PDF support, use native Anthropic or Gemini backends

This gives users clear guidance on how to resolve the issue.

Testing

The implementation has been tested to ensure:

  • Supported image formats (JPEG, PNG, GIF, WebP) work correctly
  • Unsupported formats (PDF, text, video) are properly rejected
  • Error messages are clear and actionable

🤖 Generated with Claude Code

OpenAI's Vision API only supports image formats (JPEG, PNG, GIF,
WebP) and does not support PDFs or other document types. Previously,
gptel would send any media file as an image_url, causing API errors
when PDFs were included.

This change adds MIME type validation in gptel--openai-parse-multipart
to reject unsupported formats with a clear error message, guiding users
to use native Anthropic or Gemini backends for PDF support.

Fixes karthink#929

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@jwiegley
Copy link
Contributor Author

jwiegley commented Oct 4, 2025

@karthink I don't use OpenAI through OpenRouter, so I'm not confident of these changes yet.

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.

Can not send pdf-file to the LLM (GPT-4o and Gemini 2.5 pro) through OpenRouter

1 participant