[feat] register openai as built-in openai-compatible provider#3
Merged
Conversation
The openai-compatible AI SDK provider defaulted `supportsStructuredOutputs`
to false, which downgraded every `generateObject` call to schema-less
`response_format: { type: "json_object" }`. Thinking models returned JSON
that did not satisfy strict Valibot schemas (notably MechanismAssessment's
required M1-M7 keys and TestAssessment's minLength reasons), so each call
retried up to 5x — which, multiplied across user/target/judge calls with
minute-long thinking-model latencies, looked like an infinite loop.
Mark vllm as supporting structured outputs and thread the flag through
ResolvedTarget so the AI SDK forwards the full JSON Schema for server-side
xgrammar enforcement. Expose the same toggle on `models.json` entries for
custom providers.
The 300-token per-request cap in generateUserMessage starves reasoning models: the <think> trace consumes the entire budget before any content token is emitted, so message.content comes back empty. Let the provider-level cap (`<PREFIX>_MAX_TOKENS` or models.json `maxTokens`) govern instead — that's the right place to bound generation since it scales with the model. Also bump the README's recommended VLLM_MAX_TOKENS from 8192 to 32768 and document the reasoning+answer shared budget, the `max_model_len` ceiling, and the `finish_reason="length"` → retry symptom.
…forcement Now that the hardcoded 300-token cap on user-message generation is gone, make explicit that `<PREFIX>_MAX_TOKENS` is the single knob governing every call site — and that it's the right place to budget for reasoning models. Also add a note about `supportsStructuredOutputs` for vllm so users debugging schema-validation retries know where to look.
Lets callers address OpenAI models directly via the `openai/<model-id>` slug (e.g. `openai/gpt-5-nano`) without adding a per-model `models.json` entry. Defaults to `https://api.openai.com/v1`; `OPENAI_BASE_URL` overrides for proxies. Gateway-routed OpenAI models keep their named `models.json` entries unchanged.
The `.env` file is auto-loaded by `yarn kora:env`, so the OpenAI direct path uses the same flow as the Vercel AI gateway key. Add `OPENAI_API_KEY` / `OPENAI_BASE_URL` placeholders to `.env.example` and update the README quick example to use `kora:env`.
Two tests used `openai/gpt-4o` as an example of an "unknown prefix", which is no longer true now that `openai` is a registered provider. Replace those cases with a synthetic `nonprovider/...` slug, and add a dedicated test asserting the openai prefix resolves to api.openai.com with `OPENAI_API_KEY` and structured-outputs support.
fenfenai
approved these changes
May 20, 2026
fenfenai
left a comment
There was a problem hiding this comment.
Review Summary
Reviewed 10 files, 89 additions / 10 deletions across bug detection, error handling, type design, test coverage, comment quality, and guidelines compliance.
No findings at confidence ≥75. Approving.
Positive observations
supportsStructuredOutputsis added as optional on bothOpenAICompatibleProviderandVOpenAICompatibleModelConfig, with?? falsedefaults at bothfromParsedSlugandfromConfig— safe asymmetric design (opt-in per provider, conservative for unknown configs).- The structured-output fallback in
getStructuredResponsealready handlesjson_schema-rejecting models via prompt injection +extractJson, so flipping the flag on foropenai/vllmdegrades safely. - Tests for the unknown-prefix case were correctly migrated from
openai/gpt-4oto a syntheticnonprovider/...slug — necessary and easy to forget. - Comments explain the why (e.g., the
json_objectvsjson_schemadistinction and the consequence for strictMechanismAssessmentschemas). .env.exampleand README updates align withyarn kora:env's--env-fileflow.
Lower-confidence observations (FYI, below report threshold)
generateUserMessage.tsremoval ofmaxTokens: 300also widens scope to gateway-routed user models — intentional per the PR description and updated test comment, but worth a heads-up since gateway callers have no<PREFIX>_MAX_TOKENSequivalent.- End-to-end propagation of
supportsStructuredOutputsfrom provider entry throughResolvedTargettocreateOpenAICompatibleisn't asserted by a test. The flow is short and reads correctly; minor coverage gap, not a bug.
5 tasks
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.
Summary
Follow-up to merged PR #2. Lets callers address OpenAI models directly with the slug form
openai/<model-id>(e.g.openai/gpt-5-nano) — same dispatch path asvllm/<model-id>, nomodels.jsonentry required.packages/cli/src/models/openAICompatibleProviders.ts:defaultBaseURL: https://api.openai.com/v1baseURLEnv: OPENAI_BASE_URL(override for OpenAI-compatible proxies)apiKeyEnv: OPENAI_API_KEYsupportsStructuredOutputs: true(server-sideresponse_format: { type: "json_schema" })json_schemaresponse_format for vLLM structured outputs/v1/models.env.exampledocumentsOPENAI_API_KEY/OPENAI_BASE_URLnext to the existing gateway and vLLM keys;yarn kora:envalready loads.envvianode --env-file, so OpenAI direct follows the same flow as the Vercel AI gateway.openai/gpt-4oas the example of an unknown prefix; replaced with a syntheticnonprovider/...slug. Added an explicit positive test that theopenaiprefix resolves toapi.openai.com.Gateway-routed OpenAI models (named entries like
gpt-4o,gpt-5.2:highinmodels.json) are unchanged.Test plan
yarn tsbuild— passesyarn test— 182/182 passingapi.openai.com:yarn kora run openai/gpt-5-nano openai/gpt-5-nano --judges openai/gpt-5-nano --limit 10— 10/10 scenarios scored, judgeMechanismAssessmentJSON validated server-side.vllm/Qwen3-30B-A3B-Instruct-2507— 1/1 passes.