Skip to content

feat(litellm): add image generation provider - #69958

Closed
zqchris wants to merge 4 commits into
openclaw:mainfrom
zqchris:feat/litellm-image-generation
Closed

zqchris wants to merge 4 commits into
openclaw:mainfrom
zqchris:feat/litellm-image-generation

Conversation

@zqchris

@zqchris zqchris commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Registers litellm as an image-generation provider so model refs like litellm/gpt-image-2 route through the LiteLLM proxy, and agents.defaults.imageGenerationModel.fallbacks entries of the form litellm/... resolve instead of failing with No image-generation provider registered for litellm.

LiteLLM proxies OpenAI-compatible endpoints, so this uses the same /images/generations and /images/edits shape the bundled OpenAI provider does. The existing LiteLLM API key is reused (no new auth surface). BaseUrl resolves from models.providers.litellm.baseUrl and falls back to the LITELLM_BASE_URL default already used by the text completion provider.

Private network handling

Since LiteLLM is typically deployed as a self-hosted proxy, the provider auto-allows private network when the configured baseUrl resolves to a loopback or RFC1918 address (127.0.0.1, localhost, [::1], 10.x, 192.168.x, 172.16-31.x, host.docker.internal). This matches real-world LiteLLM deployments without requiring a global OPENCLAW_PROVIDER_ALLOW_PRIVATE_NETWORK override. Public baseUrls keep normal SSRF defaults.

Defaults

  • defaultModel: gpt-image-2 (matches the upstream OpenAI default from providers: default Moonshot to Kimi 2.6 #69477-era changes)
  • Advertised sizes: legacy 256x256/512x512/1024x1024 for dall-e-3 through the new 2K/4K sizes (2048x2048, 3840x2160, etc.) for gpt-image-2
  • Both generate and edit capabilities enabled (edit accepts up to 5 input images)

Actual image models available depend on what the operator's LiteLLM proxy is configured to route — the provider just forwards requests; it does not enumerate remote models.

Contract

extensions/litellm/openclaw.plugin.json declares "contracts": { "imageGenerationProviders": ["litellm"] } so the capability is discovered through the existing manifest path used by every other image-gen provider plugin.

Test plan

  • Unit tests in extensions/litellm/image-generation-provider.test.ts cover:
    • declared id, label, default model, advertised sizes, edit enabled
    • loopback baseUrl → allowPrivateNetwork: true
    • public baseUrl → allowPrivateNetwork: false
    • count and size overrides forwarded on generate
    • edit endpoint selected when inputImages present
    • missing API key error message
  • pnpm check green (typecheck + lint + policy guards)
  • pnpm build produces a clean dist
  • Live smoke against a running LiteLLM proxy with gpt-image-2 configured (not run in CI — requires user-provided LiteLLM setup)

Registers litellm as an image-generation provider so model refs like
litellm/gpt-image-2 route through the LiteLLM proxy, and
agents.defaults.imageGenerationModel.fallbacks entries of the form
litellm/... resolve without "No image-generation provider registered
for litellm" errors.

Implementation uses the OpenAI-compatible /images/generations and
/images/edits endpoints that LiteLLM proxies for. BaseUrl resolves from
models.providers.litellm.baseUrl (default http://localhost:4000). Private
network is auto-allowed when baseUrl is a loopback/RFC1918 address, which
covers the common self-hosted LiteLLM proxy case without needing
OPENCLAW_PROVIDER_ALLOW_PRIVATE_NETWORK. Public baseUrls keep normal SSRF
defaults.

Default model is gpt-image-2 (matching upstream 4.21+ OpenAI default).
Advertises the same 2K/4K sizes OpenAI now exposes, plus legacy
256/512/1024 for dall-e-3. Supports both generate and edit.

Local patch. LiteLLM has no upstream image-generation support yet; revisit
if upstream adds one.
@greptile-apps

greptile-apps Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR registers litellm as an image-generation provider by adding image-generation-provider.ts, wiring it into index.ts, and declaring the imageGenerationProviders contract in the plugin manifest. The implementation closely mirrors the existing OpenAI image provider.

  • P1: dispatcherPolicy is not destructured from resolveProviderHttpRequestConfig and is therefore never forwarded to postJsonRequest. The OpenAI provider (the direct template) explicitly destructures and passes dispatcherPolicy — omitting it here silently bypasses any platform-level dispatcher configuration (connection pooling, proxy routing, SSRF guards) for all LiteLLM image requests.

Confidence Score: 4/5

One P1 defect (missing dispatcherPolicy forwarding) should be fixed before merging; all other changes look correct.

The implementation is well-structured and test coverage is solid. A single P1 issue — dispatcherPolicy returned by resolveProviderHttpRequestConfig is silently dropped instead of being forwarded to postJsonRequest — needs to be addressed. This is a copy-from-OpenAI-provider regression that could bypass platform-level network controls.

extensions/litellm/image-generation-provider.ts — the dispatcherPolicy destructuring and forwarding fix.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/litellm/image-generation-provider.ts
Line: 106-148

Comment:
**`dispatcherPolicy` silently dropped**

`resolveProviderHttpRequestConfig` returns a `dispatcherPolicy` alongside `baseUrl`, `allowPrivateNetwork`, and `headers`, but only three of those four fields are destructured here. The OpenAI image provider (the template for this file) explicitly destructures and forwards `dispatcherPolicy` to `postJsonRequest`. Dropping it means any platform-level dispatcher configuration (connection pooling, proxy routing, SSRF guards) is silently ignored for all LiteLLM image requests.

The fix is to destructure `dispatcherPolicy` on line 106 and pass it to `postJsonRequest` on line 141, mirroring the OpenAI provider pattern.

```suggestion
      const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } = resolveProviderHttpRequestConfig({
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(litellm): add image generation prov..." | Re-trigger Greptile

Comment on lines +106 to +148
const { baseUrl, allowPrivateNetwork, headers } = resolveProviderHttpRequestConfig({
baseUrl: resolvedBaseUrl,
defaultBaseUrl: LITELLM_BASE_URL,
allowPrivateNetwork: shouldAllowPrivateLitellmEndpoint(resolvedBaseUrl),
defaultHeaders: {
Authorization: `Bearer ${auth.apiKey}`,
},
provider: "litellm",
capability: "image",
transport: "http",
});

const model = req.model || DEFAULT_LITELLM_IMAGE_MODEL;
const count = req.count ?? 1;
const size = req.size ?? DEFAULT_SIZE;

const jsonHeaders = new Headers(headers);
jsonHeaders.set("Content-Type", "application/json");
const endpoint = isEdit ? "images/edits" : "images/generations";
const body = isEdit
? {
model,
prompt: req.prompt,
n: count,
size,
images: inputImages.map((image) => ({
image_url: toDataUrl(image.buffer, image.mimeType?.trim() || DEFAULT_OUTPUT_MIME),
})),
}
: {
model,
prompt: req.prompt,
n: count,
size,
};
const { response, release } = await postJsonRequest({
url: `${baseUrl}/${endpoint}`,
headers: jsonHeaders,
body,
timeoutMs: req.timeoutMs,
fetchFn: fetch,
allowPrivateNetwork,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 dispatcherPolicy silently dropped

resolveProviderHttpRequestConfig returns a dispatcherPolicy alongside baseUrl, allowPrivateNetwork, and headers, but only three of those four fields are destructured here. The OpenAI image provider (the template for this file) explicitly destructures and forwards dispatcherPolicy to postJsonRequest. Dropping it means any platform-level dispatcher configuration (connection pooling, proxy routing, SSRF guards) is silently ignored for all LiteLLM image requests.

The fix is to destructure dispatcherPolicy on line 106 and pass it to postJsonRequest on line 141, mirroring the OpenAI provider pattern.

Suggested change
const { baseUrl, allowPrivateNetwork, headers } = resolveProviderHttpRequestConfig({
baseUrl: resolvedBaseUrl,
defaultBaseUrl: LITELLM_BASE_URL,
allowPrivateNetwork: shouldAllowPrivateLitellmEndpoint(resolvedBaseUrl),
defaultHeaders: {
Authorization: `Bearer ${auth.apiKey}`,
},
provider: "litellm",
capability: "image",
transport: "http",
});
const model = req.model || DEFAULT_LITELLM_IMAGE_MODEL;
const count = req.count ?? 1;
const size = req.size ?? DEFAULT_SIZE;
const jsonHeaders = new Headers(headers);
jsonHeaders.set("Content-Type", "application/json");
const endpoint = isEdit ? "images/edits" : "images/generations";
const body = isEdit
? {
model,
prompt: req.prompt,
n: count,
size,
images: inputImages.map((image) => ({
image_url: toDataUrl(image.buffer, image.mimeType?.trim() || DEFAULT_OUTPUT_MIME),
})),
}
: {
model,
prompt: req.prompt,
n: count,
size,
};
const { response, release } = await postJsonRequest({
url: `${baseUrl}/${endpoint}`,
headers: jsonHeaders,
body,
timeoutMs: req.timeoutMs,
fetchFn: fetch,
allowPrivateNetwork,
});
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } = resolveProviderHttpRequestConfig({
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/litellm/image-generation-provider.ts
Line: 106-148

Comment:
**`dispatcherPolicy` silently dropped**

`resolveProviderHttpRequestConfig` returns a `dispatcherPolicy` alongside `baseUrl`, `allowPrivateNetwork`, and `headers`, but only three of those four fields are destructured here. The OpenAI image provider (the template for this file) explicitly destructures and forwards `dispatcherPolicy` to `postJsonRequest`. Dropping it means any platform-level dispatcher configuration (connection pooling, proxy routing, SSRF guards) is silently ignored for all LiteLLM image requests.

The fix is to destructure `dispatcherPolicy` on line 106 and pass it to `postJsonRequest` on line 141, mirroring the OpenAI provider pattern.

```suggestion
      const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } = resolveProviderHttpRequestConfig({
```

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bba6ed2982

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +42 to +46
lower.startsWith("http://127.0.0.1") ||
lower.startsWith("http://localhost") ||
lower.startsWith("http://[::1]") ||
lower.startsWith("http://10.") ||
lower.startsWith("http://192.168.") ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle HTTPS private LiteLLM base URLs

The private-network auto-allow check only matches http://... prefixes, so a secure local/private proxy URL like https://127.0.0.1:4000 or https://192.168.1.10 is treated as public. In that case allowPrivateNetwork stays false, and the SSRF guard will block the request even though this feature is meant to support self-hosted LiteLLM endpoints on loopback/RFC1918 addresses.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8133ff1de4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +57 to +59
lower.startsWith("10.") ||
lower.startsWith("192.168.") ||
/^172\.(1[6-9]|2[0-9]|3[0-1])\./.test(lower) ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict private-network auto-allow to literal private IPs

The private-network heuristic currently uses hostname prefix checks (startsWith("10."), startsWith("192.168."), and the 172.* regex), so non-IP public hostnames like 10.example.com or 172.16.attacker.tld are treated as private and force allowPrivateNetwork: true. In that scenario, SSRF protection no longer blocks private-address DNS resolutions for that host, which can unintentionally permit internal-network routing via DNS-controlled domains. This check should only auto-allow exact localhost names and literal private IPs.

Useful? React with 👍 / 👎.

@zqchris
zqchris requested review from a team as code owners April 22, 2026 09:27
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: whatsapp-web Channel integration: whatsapp-web app: android App: android app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime extensions: memory-core Extension: memory-core cli CLI command changes labels Apr 22, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing this PR because it looks dirty (too many unrelated or unexpected changes). This usually happens when a branch picks up unrelated commits or a merge went sideways. Please recreate the PR from a clean branch.

@zqchris
zqchris deleted the feat/litellm-image-generation branch April 22, 2026 10:04
@prtags

prtags Bot commented Apr 23, 2026

Copy link
Copy Markdown

Related work from PRtags group tidy-shepherd-n6wq

Title: Open PR duplicate: LiteLLM image generation provider

Number Title
#69958* feat(litellm): add image generation provider
#70113 feat(litellm): add image generation provider
#70117 feat(litellm): add image generation provider
#70246 feat(litellm): add image generation provider

* This PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: android App: android app: macos App: macos app: web-ui App: web-ui channel: discord Channel integration: discord channel: feishu Channel integration: feishu channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: irc channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: qqbot channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: whatsapp-web Channel integration: whatsapp-web cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: anthropic extensions: codex extensions: device-pair extensions: kilocode extensions: memory-core Extension: memory-core extensions: minimax extensions: moonshot extensions: openai extensions: qa-lab extensions: tencent extensions: tokenjuice Changes to the bundled tokenjuice extension extensions: vercel-ai-gateway gateway Gateway runtime scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant