Repository navigation
fix(images): use node base_url + resolve prefix for custom image providers (#3205) - #3208
Conversation
…mage providers (#3205) The image-generation handler read credentials.baseUrl (always undefined), so custom OpenAI-compatible image providers fell back to the Gemini endpoint (401). Resolve from providerSpecificData.baseUrl like the chat path, and rewrite prefix/model to the internal node id before the exact-id lookup. Co-authored-by: ngocquynh85 <ngocquynh85@users.noreply.github.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a02ffb5a1
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!parseImageModel(body.model).provider) { | ||
| body.model = await resolveImageModelPrefix(body.model); |
There was a problem hiding this comment.
Normalize custom image model before policy checks
When a client uses the newly supported user prefix (myImg/gpt-image-2) with an API key that has model restrictions or disableNonPublicModels, the policy check still runs against the prefix before it is rewritten to the internal <nodeId>/<model> id stored in customModels. That makes a key configured for the model ids returned by GET /v1/images/generations reject valid prefixed requests (and also evaluates token limits against the wrong model name). Move the prefix resolution ahead of enforceApiKeyPolicy or have the policy evaluate the resolved id.
Useful? React with 👍 / 👎.
| baseUrl: resolveImageBaseUrl( | ||
| credentials, | ||
| `https://generativelanguage.googleapis.com/v1beta/openai/images/generations` | ||
| ), |
There was a problem hiding this comment.
Honor custom endpoint paths for image nodes
Custom OpenAI-compatible nodes can store a non-default endpoint path in providerSpecificData.chatPath, but this resolver only uses the base URL and then always appends /images/generations. For an image node configured with a gateway-specific path such as baseUrl=https://gateway.example/v1 and chatPath=/custom/images, requests are sent to /v1/images/generations instead of the configured endpoint, so those otherwise valid custom providers still fail.
Useful? React with 👍 / 👎.
Code Review SummaryStatus: No Additional Issues Found | Recommendation: Code looks sound Overview
Files Reviewed (3 files)
Other Observations (not in diff)No issues in unchanged code that require attention. Notes
Reviewed by step-3.7-flash-20260528 · 858,084 tokens |
| // Prefer an explicit user-defined prefix match; node.id (internal UUID) is | ||
| // already handled by the exact-id loop, so only rewrite when the prefix | ||
| // differs from the node id. | ||
| const matched = nodes.find((node: any) => node.prefix === prefixPart); |
There was a problem hiding this comment.
WARNING: node: any bypasses TypeScript type safety
getProviderNodes returns typed objects with prefix, id, etc. Using any discards that type information. Consider typing the parameter properly (e.g. using the return type of getProviderNodes) so the compiler can catch shape mismatches if the schema changes.
| if (!rest) return modelStr; | ||
|
|
||
| try { | ||
| const nodes = await getProviderNodes({ type: "openai-compatible" }); |
There was a problem hiding this comment.
SUGGESTION: getProviderNodes({ type: "openai-compatible" }) hits the DB on every prefixed-model request
If this code path is exercised frequently, consider caching the node list (e.g. via readCache.ts or an in-memory cache with invalidation on provider changes) to avoid repeated SQLite reads in the request hot path.
…mage providers (cheaper-inference#3205) (cheaper-inference#3208) The image-generation handler read credentials.baseUrl (always undefined), so custom OpenAI-compatible image providers fell back to the Gemini endpoint (401). Resolve from providerSpecificData.baseUrl like the chat path, and rewrite prefix/model to the internal node id before the exact-id lookup. Co-authored-by: ngocquynh85 <ngocquynh85@users.noreply.github.com>
…mage providers (cheaper-inference#3205) (cheaper-inference#3208) The image-generation handler read credentials.baseUrl (always undefined), so custom OpenAI-compatible image providers fell back to the Gemini endpoint (401). Resolve from providerSpecificData.baseUrl like the chat path, and rewrite prefix/model to the internal node id before the exact-id lookup. Co-authored-by: ngocquynh85 <ngocquynh85@users.noreply.github.com>
…mage providers (cheaper-inference#3205) (cheaper-inference#3208) The image-generation handler read credentials.baseUrl (always undefined), so custom OpenAI-compatible image providers fell back to the Gemini endpoint (401). Resolve from providerSpecificData.baseUrl like the chat path, and rewrite prefix/model to the internal node id before the exact-id lookup. Co-authored-by: ngocquynh85 <ngocquynh85@users.noreply.github.com>
Closes #3205
Custom image-generation providers read
credentials.baseUrl(always undefined) → fell back to the Gemini endpoint (401). Now resolvesproviderSpecificData.baseUrllike the chat path, and rewritesprefix/modelto the internal node id before the exact-id lookup.Test:
tests/unit/image-generation-baseurl-3205.test.ts. Thanks @ngocquynh85.