Skip to content

fix(plugins): support OPENAI_IMAGE_API_MODEL env var + base_url config for third-party backends#18796

Open
y0shua1ee wants to merge 1 commit into
NousResearch:mainfrom
y0shua1ee:fix/openai-image-api-model-override
Open

fix(plugins): support OPENAI_IMAGE_API_MODEL env var + base_url config for third-party backends#18796
y0shua1ee wants to merge 1 commit into
NousResearch:mainfrom
y0shua1ee:fix/openai-image-api-model-override

Conversation

@y0shua1ee

@y0shua1ee y0shua1ee commented May 2, 2026

Copy link
Copy Markdown
Contributor

Problem

The OpenAI image gen plugin hardcodes API_MODEL = "gpt-image-2" in the API request payload, making it impossible to use third-party OpenAI-compatible backends (e.g., Krill AI, OpenRouter image endpoints) that expect different model identifiers.

# Before this PR — always sends "gpt-image-2" regardless of config
payload = {"model": API_MODEL, ...}
client = openai.OpenAI()  # no base_url support from config

Closes #18793

Solution

Three new escape hatches, fully backward-compatible — defaults unchanged:

API model override

Priority Source
1 OPENAI_IMAGE_API_MODEL env var
2 image_gen.openai.api_model config key
3 API_MODEL (default: gpt-image-2)

Base URL

Priority Source
1 OPENAI_BASE_URL env var (standard SDK behaviour)
2 image_gen.openai.base_url config key
3 None → api.openai.com

Usage example (Krill AI)

# config.yaml
image_gen:
  provider: openai
  openai:
    api_model: gpt-image-2-1k-medium
    base_url: https://api.krill-ai.com/v1

Or via env var:

export OPENAI_IMAGE_API_MODEL=gpt-image-2-1k-medium

Changes

  • Added _resolve_api_model() — resolves the model name for the API request
  • Added _resolve_base_url() — resolves the base URL for the OpenAI client
  • Updated generate() to use resolved values instead of hardcoded constants
  • Updated module docstring with new precedence rules

No breaking changes. Default behaviour unchanged.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins tool/vision Vision analysis and image generation labels May 2, 2026
@y0shua1ee y0shua1ee force-pushed the fix/openai-image-api-model-override branch from 5992c0b to 815f9f2 Compare May 9, 2026 05:03
@y0shua1ee

y0shua1ee commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased and updated this PR against the current main after #21273 landed.

What changed in this revision:

  • Keeps the existing virtual tier IDs (gpt-image-2-low, gpt-image-2-medium, gpt-image-2-high) as quality selectors.
  • Separates those tier IDs from the actual model field sent to images.generate.
  • Honors feat(image-gen): honor image_gen.model from config.yaml (salvage #19376) #21273's dispatcher-provided model kwarg:
    • if it is one of the virtual tier IDs, it selects the quality tier;
    • if it is not a virtual tier ID, it is treated as the actual API model for OpenAI-compatible backends.
  • Keeps explicit escape hatches with higher precedence:
    • OPENAI_IMAGE_API_MODEL
    • image_gen.openai.api_model
  • Adds base URL support through:
    • OPENAI_BASE_URL
    • image_gen.openai.base_url
  • Adds tests for API model resolution, base URL resolution, provider.generate(...), and dispatcher model forwarding.

Local verification:

python -m pytest -o addopts= tests/plugins/image_gen/test_openai_provider.py -q
# 37 passed

python -m pytest -o addopts= tests/plugins/image_gen -q
# 74 passed

python -m pytest -o addopts= tests/tools -k image -q
# 187 passed, 7 skipped

python -m ruff check plugins/image_gen/openai/__init__.py tests/plugins/image_gen/test_openai_provider.py tests/tools/test_image_generation_plugin_dispatch.py
# All checks passed

This should make the PR complementary to #21273 rather than conflicting with it: #21273 forwards image_gen.model; this plugin now actually interprets that forwarded value correctly while still supporting provider-specific api_model / base_url config for third-party OpenAI-compatible image endpoints.

CI note after the latest push:

  • ruff enforcement (blocking) passed.
  • nix ubuntu/macOS, e2e, supply-chain scan, Windows footguns, attribution, and Docker build jobs passed.
  • ruff + ty diff failed only while trying to post its PR comment (Resource not accessible by integration on issues/.../comments); the generated summary reported no new ruff issues and labels ty diagnostics as warnings.
  • test failed in two unchanged areas outside this PR's diff:
    • tests/gateway/test_restart_drain.py::test_restart_command_while_busy_requests_drain_without_interrupt
    • tests/hermes_cli/test_tencent_tokenhub_provider.py::TestTencentTokenhubContextLength::test_hy3_preview_context_length

This PR's changed files remain limited to:

plugins/image_gen/openai/__init__.py
tests/plugins/image_gen/test_openai_provider.py
tests/tools/test_image_generation_plugin_dispatch.py

Split the OpenAI image plugin's virtual quality-tier IDs from the actual API model sent in images.generate requests.

This keeps gpt-image-2-low/medium/high as UI/config tier selectors while allowing OpenAI-compatible backends to set the real payload model via OPENAI_IMAGE_API_MODEL, image_gen.openai.api_model, or the dispatcher-provided image_gen.model from NousResearch#21273 when it is not one of the virtual tier IDs.

Also pass OPENAI_BASE_URL or image_gen.openai.base_url into openai.OpenAI(), and cover the resolver, provider.generate, and dispatcher model forwarding paths with tests.

Closes: NousResearch#18793
@y0shua1ee y0shua1ee force-pushed the fix/openai-image-api-model-override branch from 815f9f2 to 8788925 Compare May 29, 2026 07:06
@y0shua1ee

Copy link
Copy Markdown
Contributor Author

Rebased this PR and refreshed CI.

Status after the refresh:

  • Head: 87889255b
  • Merge state: CLEAN
  • Checks: 18 success, 2 skipped

Local verification run before pushing:

uv run --with ruff ruff check plugins/image_gen/openai/__init__.py tests/plugins/image_gen/test_openai_provider.py tests/tools/test_image_generation_plugin_dispatch.py
uv run --extra dev --with pytest-xdist python -m pytest tests/plugins/image_gen/test_openai_provider.py tests/tools/test_image_generation_plugin_dispatch.py tests/gateway/test_restart_drain.py::test_restart_command_while_busy_requests_drain_without_interrupt tests/hermes_cli/test_tencent_tokenhub_provider.py::TestTencentTokenhubContextLength::test_hy3_preview_has_registered_context_length -q --tb=short -n 0

The previous red checks were from the stale branch state; the fork-comment permission issue in the lint summary path is no longer present on the refreshed run.

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

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have tool/vision Vision analysis and image generation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

image_gen openai plugin: API_MODEL hardcoded, breaks third-party OpenAI-compatible backends

2 participants