Add OpenAI-compatible BYOK provider and routing support - #67
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — one minor consistency suggestion inline.
Reviewed changes — adds a generic openai-compatible/byok routing slug so runs can target any OpenAI-compatible /v1 gateway via OPENAI_COMPATIBLE_* secrets, wired through the existing Bedrock/Vertex routing-slug machinery.
- Register the
openai-compatibleprovider — newprovider()entry inmodels.tswith a singlebyokrouting model, the"openai-compatible"ModelRoutingdiscriminant, andOPENAI_COMPATIBLE_*env constants. - Resolve the slug —
resolveSluginutils/agent.tsmapsopenai-compatible/byoktoopenai-compatible/<OPENAI_COMPATIBLE_MODEL_ID>, throwing with the full missing-var list when config is absent. - Inject the OpenCode provider —
buildSecurityConfigis refactored into an exported, testablebuildOpenCodeConfigthat adds an@ai-sdk/openai-compatibleprovider block (baseURL/apiKey/model) when the active route matches. - Auth + access gates —
validateAgentApiKeygains a dedicated setup validator (handling both the slug and the resolved slashed specifier) and tightens the slash-less fall-through so unmatched IDs no longer always hit Bedrock validation;decideModelAccessnow treats any alias with aroutingflag as byok-authorized rather than relying on the slash heuristic. - Docs + tests — README BYOK section (LiteLLM called out only as an example) plus new unit tests across
models,agent,apiKeys, and a newmodelAccess.test.ts.
The routing-slug, auth-validation, and model-access changes are consistent with the existing Bedrock/Vertex patterns and are well covered by the new tests. The slash-less fall-through tightening in validateAgentApiKey is intentional and safe — bedrock/vertex resolved IDs still match their env sentinels, and previously-unmatched bare words now surface a generic missing-key error instead of a misleading Bedrock one.
Claude Opus (free via Pullfrog for OSS) | 𝕏
Trailing newlines on pasted GitHub secrets would otherwise leak verbatim into the OpenCode provider options. Also add a unit test.

Closes: #66
Add an OpenAI-compatible bring-your-own-key provider that routes Pullfrog through any OpenAI-compatible
/v1endpoint using repository secrets for the API key, base URL, and model ID. Fix routing-slug handling soopenai-compatible/byokresolves to the configured model and passes authorization checks.Note
Medium Risk
Changes model resolution, credential validation, and OpenCode provider wiring on the inference path, but follows existing Bedrock/Vertex routing patterns and is covered by targeted tests.
Overview
Introduces OpenAI-compatible BYOK so repos can point Pullfrog at any
/v1gateway (e.g. LiteLLM) viaOPENAI_COMPATIBLE_API_KEY,OPENAI_COMPATIBLE_BASE_URL, andOPENAI_COMPATIBLE_MODEL_ID, usingPULLFROG_MODEL: openai-compatible/byok.The model registry gains an
openai-compatibleprovider and routing type;resolveModelmaps the slug toopenai-compatible/<model-id>. OpenCode v2 refactors config building into exportedbuildOpenCodeConfig, which injects the dynamicopenai-compatibleprovider (base URL, API key trimmed) when that route is active.Pre-run validation mirrors Bedrock/Vertex:
validateAgentApiKeyrequires all three vars for the slug and resolved model.decideModelAccesstreats any alias with aroutingflag as BYOK-authorized so slashed resolved IDs are not rejected against OpenCode's staticauthorizedset.README documents the workflow
envblock; unit tests cover registry, resolution, OpenCode config, API keys, and model access.Reviewed by Cursor Bugbot for commit 8963ce8. Bugbot is set up for automated code reviews on this repo. Configure here.