#16018: feat: add image support to /v1/chat/completions endpoint
gateway
stale
size: S
Cluster:
OpenClaw Plugin Enhancements
## 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
#16346: feat: support image attachments in OpenAI chat completions endpoint
by sh1nj1 · 2026-02-14
90.5%
#16777: feat(gateway): add multimodal image support to /v1/chat/completions
by dzianisv · 2026-02-15
88.9%
#9598: fix(agents): check base64 string length against 5MB API limit
by BlockBB · 2026-02-05
77.6%
#10394: feat(mattermost): add image attachment support for inbound messages
by mithril-logic · 2026-02-06
76.1%
#8284: Fix: Webchat images now persist after sending
by vishaltandale00 · 2026-02-03
75.2%
#4534: fix: packaging and OpenAI vision format conversion
by SalimBinYousuf1 · 2026-01-30
74.9%
#22113: feat: support non-image file attachments in webchat chat.send
by Kt-L · 2026-02-20
74.4%
#22333: Fix webchat inline image rendering and size handling
by AIflow-Labs · 2026-02-21
74.0%
#20913: fix: intercept Discord embed images to enforce mediaMaxMb
by MumuTW · 2026-02-19
73.8%
#10441: webchat: switch file uploads to HTTP /uploads
by supernewbilityxht1 · 2026-02-06
73.5%