Repository navigation
feat(py): add OpenAICompatible for any OpenAI-compatible server, matching JS and Go - #258
Merged
Merged
Conversation
This was referenced Nov 30, 2026
huangjeff5
force-pushed
the
feat/py-openai-compatible-plugin
branch
from
December 1, 2026 20:23
8caa53a to
1049d38
Compare
huangjeff5
force-pushed
the
feat/py-openai-compatible-plugin
branch
from
December 1, 2026 21:20
1049d38 to
4ccad82
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-plugin
branch
from
December 1, 2026 21:37
4ccad82 to
b65f990
Compare
huangjeff5
enabled stacked auto-merge (squash)
December 1, 2026 21:52
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 OpenAI-compatible server (OpenRouter, Together, Groq, vLLM, LiteLLM, local servers) under a caller-chosen namespace. This matches JS'sopenAICompatible({ name, baseURL, apiKey })and Go'scompat_oai.OpenAICompatible{Provider, BaseURL, APIKey}.Previously,
OpenAI(base_url=...)was the only way to hit these servers, and its OpenAI-specific assumptions broke non-OpenAI endpoints:OpenAI.gpt('openai/gpt-4o')stripped both prefixes and sentgpt-4oto OpenRouter;google/gemini-2.5-promatched the-profilter);/modelsbroke Dev UI model listing;openai/namespace.Changes
OpenAICompatibleplugin: Requiresnameandbase_url, registering models and embedders under<name>/<id>.namerejects/,:, whitespace, and control characters;base_urlrejects empty or blank strings.ai.generateresolves chat models andai.embedresolves embedders.OpenAICompatibleinstances can run alongside each other andOpenAI().instance.model(name, config=...)returns a typedOpenAIConfigref (e.g.openrouter.model('meta-llama/...')) and never strips<name>/(so provider-prefixed IDs likeopenrouter/autostay intact)._COMPATIBLE_SUPPORTS): Declaresmultiturn,media,tools,tool_choice,system_role,output=['json', 'text'], andconstrained=Noneso Dev UI capability checks work without assuming native JSON Schema support./modelslisting:init()registers nothing. Dev UI listing queries/models, deduplicates IDs in server order, classifies IDs containingembed(case-insensitive) as embedders and the rest as chat models, and logs a warning returning[](without caching the failure) on missing/models, HTTP errors, or malformed HTTP 200 payloads.api_keyaccepts a string, an async callable (awaited before each request for expiring tokens), orNone(sends a placeholder for keyless local servers; invalid types raiseTypeError).OPENAI_API_KEY(includingclient_options={'api_key': None}),OPENAI_ORG_ID, orOPENAI_PROJECT_ID.context.secretsoverrides the plugin key and stripsOpenAI-Organization/OpenAI-Projectheaders on tenant calls; refused withFAILED_PRECONDITIONifAuthorizationis pinned indefault_headers.embed_textshelper used by bothOpenAIandOpenAICompatible(preserving Mistral'soutput_dimensionhandling on Mistral hosts).openaifloor from>=1.99.2to>=1.106.0, the first version whoseapi_keyaccepts an async callable.OpenAI(base_url=...)docs to proxies/gateways in front of OpenAI.Decisions
OpenAICompatibleclass instead of overloadingOpenAI:OpenAIcarries OpenAI's static catalog, name-based routing to image/TTS/STT endpoints, and OpenAI-specific filters. Adding passthrough mode there would require branching aroundbase_urlthroughout the plugin. A dedicated class keeps the passthrough path clean and aligns with JS and Go.nameandbase_urlfor generic servers: Requiringnameavoidsopenai/namespace collisions andopenai/openai/...ambiguity; requiringbase_urlprevents accidentally routing to OpenAI's API. Neither field falls back to environment variables. (In feat(py): serve Model Garden's OpenAI-compatible models via OpenAICompatible(backend=GoogleCloud()) #259,backend=GoogleCloud()supplies its own endpoint and defaultsnameto'modelgarden', so both become optional when a backend is passed.)Verification
packages/genkit-openai+tests/version_bounds_guard_test.py— 1,098 passed.ruff,ty,pyrefly(0 errors),scripts/check_consistency.py,uv lock --check, andaddlicense -checkall pass (pyrightruns in CI).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
#259 (
OpenAICompatible(backend=GoogleCloud(...))) and #260 (deprecategenkit-vertexai) stack on top of this PR.