Repository navigation
feat(py): add OpenAICompatible for any OpenAI-compatible server, matching JS and Go - #187
Closed
huangjeff5 wants to merge 1 commit into
Closed
huangjeff5 wants to merge 1 commit into
huangjeff5 wants to merge 1 commit into
Conversation
This was referenced Nov 25, 2026
huangjeff5
force-pushed
the
feat/py-openai-compatible
branch
from
November 30, 2026 19:57
3edc451 to
9fe4bc7
Compare
…hing JS and Go OpenAICompatible(name=..., base_url=..., api_key=...) registers a server's models and embedders as <name>/<id> and sends <id> as written. No built-in catalog or OpenAI-only filters; the Dev UI lists /models and survives a server without it. api_key takes a string, an async function, or None (never reads OPENAI_API_KEY). OpenAI and OpenAICompatible share one embed helper. The openai floor moves to 1.106.0, the first release with async api_key.
huangjeff5
force-pushed
the
feat/py-openai-compatible
branch
from
November 30, 2026 19:59
9fe4bc7 to
10b6038
Compare
This was referenced Nov 30, 2026
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenAICompatible(name=..., base_url=..., api_key=...)connects any server that speaks the OpenAI API (OpenRouter, Together, Groq, vLLM, LiteLLM, a local model server) under a name you pick. It's the same shape as JS'sopenAICompatible({ name, baseURL, apiKey })and Go'scompat_oai.OpenAICompatible{Provider, BaseURL, APIKey}.Until now,
OpenAI(base_url=...)was the only way to reach those servers, and the OpenAI-specific plugin leaked into every one:OpenAI.gpt('openai/gpt-4o')stripped both prefixes and sentgpt-4oto OpenRouter;google/gemini-2.5-prowas dropped for its-prosuffix);/modelsbroke the Dev UI list;openai/.Changes
OpenAICompatible.nameandbase_urlare required, and models and embedders register as<name>/<id>.<id>goes to the server exactly as written, with no prefix stripping and no guessing the model kind from its name.ai.generateresolves chat models andai.embedresolves embedders, by kind.OpenAI()coexist.model(name, config=...)on the instance returns anOpenAIConfigref (openrouter.model('meta-llama/...')). It's an instance method because the namespace belongs to the instance.init()registers nothing. The Dev UI lists what the server's/modelsreturns: ids containingembedas embedders, everything else as chat models. A server without/models, or one that rejects the call, lists nothing and logs a warning. The failure isn't cached, so the next listing tries again.api_keytakes a string, an async function, orNone.Nonesends a placeholder, for servers that need no key.OPENAI_API_KEYis never read, so an OpenAI key can't reach another server.context.secretskey replaces the plugin key for that call.OpenAI. The embed body moved into one helper (embed_texts) that both plugins call. A compatible server on Mistral's own host still gets Mistral'soutput_dimensionfield.openaifloor raised from>=1.60.0to>=1.106.0. 1.106 is the first release whoseapi_keyaccepts an async function. 1.105 accepts onlystr | None.OpenAI(base_url=...)is now described as a proxy or gateway in front of OpenAI, pointing toOpenAICompatiblefor anything else.Decisions
OpenAI(name=...):OpenAIis the OpenAI-specific plugin, with OpenAI's catalog, name-based routing to image/TTS/STT, and OpenAI-only filters. Adding passthrough to it would mean "ifbase_urlis set, skip the catalog and filters" branches throughout. A separate class has none of that by construction, and it matches the JS and Go split, whereopenAI()is a wrapper with the catalog on top ofopenAICompatible.nameis required: The name is the namespace. Defaulting it toopenaiwould bring back the one-per-app collision and theopenai/openai/...ambiguity. JS requiresname, and Go requiresProvider.base_urlis required: Without it, the plugin would quietly target OpenAI's API, which is whatOpenAI()is for. No environment variable is read for either field, so what the constructor says is where calls go.Verification
packages/genkit-openai: 620 passed (602 existing, 18 new inopenai_compatible_test.py). The new tests go throughai.generateandai.embedagainst a fake HTTP server. They pin:openai/-prefixed and-proids, by both string and typed ref;OpenAI()and a second instance;init();/modelslisting, its caching, and the no-/modelsfallback;OPENAI_API_KEYnever sent;context.secretsreplacing the plugin key;_compatible.py, one at a time (14 mutants), and reran the suite. Every mutant fails a test.packages/genkit-vertexai53 passed, andtests/version_bounds_guard_test.py30 passed.scripts/check_consistency.pyanduv lock --checkpass.packages/genkit-openai._models/_utils.py:476. That file is unchanged, and the error is the same onmain.Breaking changes
None to the API. Installs now need
openai>=1.106.0.OpenAI(base_url=...)behaves the same; only its docs changed.Follow-up
#188 (
OpenAICompatible(backend=GoogleCloud(...))) is stacked on this PR, and #185 deprecatesgenkit-vertexaionce #151, #187, and #188 land.