Skip to content

Add OpenAI-compatible BYOK provider and routing support - #67

Open
overbit wants to merge 3 commits into
pullfrog:mainfrom
overbit:openai-compatible-provider
Open

Add OpenAI-compatible BYOK provider and routing support#67
overbit wants to merge 3 commits into
pullfrog:mainfrom
overbit:openai-compatible-provider

Conversation

@overbit

@overbit overbit commented Jul 20, 2026

Copy link
Copy Markdown

Closes: #66

Add an OpenAI-compatible bring-your-own-key provider that routes Pullfrog through any OpenAI-compatible /v1 endpoint using repository secrets for the API key, base URL, and model ID. Fix routing-slug handling so openai-compatible/byok resolves 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 /v1 gateway (e.g. LiteLLM) via OPENAI_COMPATIBLE_API_KEY, OPENAI_COMPATIBLE_BASE_URL, and OPENAI_COMPATIBLE_MODEL_ID, using PULLFROG_MODEL: openai-compatible/byok.

The model registry gains an openai-compatible provider and routing type; resolveModel maps the slug to openai-compatible/<model-id>. OpenCode v2 refactors config building into exported buildOpenCodeConfig, which injects the dynamic openai-compatible provider (base URL, API key trimmed) when that route is active.

Pre-run validation mirrors Bedrock/Vertex: validateAgentApiKey requires all three vars for the slug and resolved model. decideModelAccess treats any alias with a routing flag as BYOK-authorized so slashed resolved IDs are not rejected against OpenCode's static authorized set.

README documents the workflow env block; 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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-compatible provider — new provider() entry in models.ts with a single byok routing model, the "openai-compatible" ModelRouting discriminant, and OPENAI_COMPATIBLE_* env constants.
  • Resolve the slugresolveSlug in utils/agent.ts maps openai-compatible/byok to openai-compatible/<OPENAI_COMPATIBLE_MODEL_ID>, throwing with the full missing-var list when config is absent.
  • Inject the OpenCode providerbuildSecurityConfig is refactored into an exported, testable buildOpenCodeConfig that adds an @ai-sdk/openai-compatible provider block (baseURL/apiKey/model) when the active route matches.
  • Auth + access gatesvalidateAgentApiKey gains 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; decideModelAccess now treats any alias with a routing flag 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 new modelAccess.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.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using Claude Opus (free via Pullfrog for OSS) | 𝕏

Comment thread agents/opencode_v2.ts
Trailing newlines on pasted GitHub secrets would otherwise leak verbatim into the OpenCode provider options. Also add a unit test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: OAI-Compatible / LiteLLM support

1 participant