Skip to content

feat(ai): apiKey: false for keyless providers - #60770

Merged
rekram1-node merged 1 commit into
devfrom
apikey-false
Oct 31, 2026
Merged

rekram1-node merged 1 commit into
devfrom
apikey-false

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A provider that needs no key (a local server, a gateway that authenticates by header) had no way to say so. Leaving the key out failed with Missing auth credential: apiKey, and passing apiKey: false crashed.

Change

apiKey: false means "no key on purpose": no env lookup, no auth header from the package, no error. Omitted or "" keeps today's behavior.

OpenAICompatible.model("local", { apiKey: false, baseURL: "http://127.0.0.1:8080/v1" })
OpenAICompatible.configure({ apiKey: false, baseURL, headers: { "x-gateway-token": "t" } }) // sends only that header
 AuthOptions.apiKey(options, envVars, apply)   // new shared helper; bearer() wraps it
   auth override?        -> use it
+  apiKey === false      -> Auth.none
   else                  -> apiKey ?? env vars, rendered by apply

Covered: every provider on the shared helper (OpenAI, OpenAI-compatible chat/responses, xAI, Groq, DeepSeek, OpenRouter, Vercel AI Gateway, Cloudflare Workers AI, Mistral, Cohere, Alibaba, Moonshot, MiniMax, Z.ai, Meta, Venice, etc.), plus Anthropic and Anthropic-compatible (x-api-key), Google (x-goog-api-key), Azure (api-key), Cloudflare AI Gateway, ElevenLabs, Deepgram and AssemblyAI. Image, decision and other media routes reuse the same auth, so they honor it too.

Out of scope

Verification

  • New offline test/keyless-auth.test.ts against a local Bun.serve stub: omitted key still errors; apiKey: false succeeds with no Authorization (chat + image) and no x-api-key (Anthropic); custom header is the only one sent.
  • Type tests in test/auth-options.types.ts.
  • bun test in packages/ai (2000 pass), bun typecheck + typecheck:tsc in ai and core, bun run check.

Added by the opencode bot (AI-generated).

Related: #42790

Public API: @opencode/ai: provider apiKey options accept false; adds AuthOptions.apiKey helper and AuthOptions.ApiKey type (backwards compatible)

@opencodejr opencodejr 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.

Looks sound. apiKey: false goes through the new shared AuthOptions.apiKey helper. I copied the new keyless test onto the base branch: its four apiKey: false cases fail there (only the omitted-key case passes), and all five pass with this change. The full packages/ai suite passes (2000 pass), and typecheck:tsc is clean in ai and core. No hand-written Auth.optional key lookups remain outside the helper. Vertex and Bedrock keep their own auth, and their types still reject false. The Cloudflare gateway order (gatewayApiKey first, then apiKey) and Azure's removal of authorization both behave correctly.

Public API (@opencode/ai, backwards compatible): apiKey now also accepts false (string → string | false on provider Config/Settings, and on OptionalApiKeyAuth/RequiredApiKeyAuth). AuthOptions.apiKey(options, envVars, apply) and the AuthOptions.ApiKey type are new. AuthOptions.bearer keeps its signature. Existing callers are unaffected.

No blocking concerns.

Related: #42790

@rekram1-node
rekram1-node merged commit 12f7e1b into dev Oct 31, 2026
23 checks passed
@rekram1-node
rekram1-node deleted the apikey-false branch October 31, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant