← Back to PRs

#16018: feat: add image support to /v1/chat/completions endpoint

by sebastienb open 2026-02-14 05:25 View on GitHub →
gateway stale size: S
## Summary The OpenAI-compatible `/v1/chat/completions` endpoint silently drops `image_url` content parts and has a 1MB body size limit that blocks base64-encoded images. Meanwhile, the `/v1/responses` endpoint and WebSocket handlers already support images correctly. This PR wires image support into the chat completions endpoint: - **New `extractImagesFromOpenAiMessages()` function** — parses `image_url` content parts from the last user message, handling both `data:image/...;base64,...` URIs (inline extraction) and `https://` URLs (via the existing `extractImageContentFromSource` helper with default image limits) - **Body size limit bumped from 1MB to 20MB** — matches `/v1/responses` default, allows base64-encoded images through - **Images passed to `agentCommand`** in both streaming and non-streaming code paths Only images from the last user message are extracted, consistent with how `buildAgentPrompt` only uses the last user entry for the current prompt. ## Test plan - [ ] Send a text-only message via `/v1/chat/completions` — should work as before (regression check) - [ ] Send a message with `image_url` content part using a `data:` URI — agent should describe/respond to the image - [ ] Send a message with `image_url` content part using an `https://` URL — image should be fetched and forwarded - [ ] Send a large base64 image (>1MB) — should succeed with the new 20MB limit - [ ] Streaming mode with images — verify images are passed through in the streaming path too 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Adds image support to the OpenAI-compatible `/v1/chat/completions` endpoint by extracting `image_url` content parts from the last user message. The implementation handles both base64 data URIs (inline extraction) and HTTPS URLs (via the existing `extractImageContentFromSource` helper with SSRF protection). The body size limit is increased from 1MB to 20MB to accommodate base64-encoded images, matching the `/v1/responses` endpoint's default limit. Key changes: - New `extractImagesFromOpenAiMessages()` function extracts images from the last user message only (consistent with how `buildAgentPrompt` works) - Images are passed to `agentCommand` in both streaming and non-streaming paths - Failed image fetches are silently skipped to avoid blocking the request - Proper type guards and validation throughout <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with low risk - The implementation reuses existing, battle-tested image extraction helpers with proper SSRF protection. The changes are focused and follow the same patterns as the `/v1/responses` endpoint. Error handling is appropriate (failed images don't block requests). The 20MB body limit increase is justified and matches other endpoints. - No files require special attention <sub>Last reviewed commit: 9969867</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs