@opencode/ai 0.0.0-dev-414 → 0.0.0-dev-420

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +2 -0
  2. package/dist/protocols/gemini.js +14 -9
  3. package/dist/protocols/google-interactions.d.ts +8 -4
  4. package/dist/protocols/google-interactions.js +36 -21
  5. package/dist/providers/alibaba.d.ts +1 -1
  6. package/dist/providers/anthropic-compatible.d.ts +2 -2
  7. package/dist/providers/anthropic-compatible.js +2 -5
  8. package/dist/providers/anthropic.d.ts +2 -2
  9. package/dist/providers/anthropic.js +2 -7
  10. package/dist/providers/assemblyai.d.ts +1 -1
  11. package/dist/providers/assemblyai.js +2 -7
  12. package/dist/providers/azure.d.ts +1 -1
  13. package/dist/providers/azure.js +2 -4
  14. package/dist/providers/baseten.d.ts +1 -1
  15. package/dist/providers/cerebras.d.ts +1 -1
  16. package/dist/providers/cloudflare-ai-gateway.d.ts +2 -2
  17. package/dist/providers/cloudflare-ai-gateway.js +4 -5
  18. package/dist/providers/cloudflare-workers-ai.d.ts +1 -1
  19. package/dist/providers/cohere.d.ts +1 -1
  20. package/dist/providers/deepgram.d.ts +1 -1
  21. package/dist/providers/deepgram.js +2 -7
  22. package/dist/providers/deepinfra.d.ts +1 -1
  23. package/dist/providers/deepseek.d.ts +1 -1
  24. package/dist/providers/digitalocean.d.ts +1 -1
  25. package/dist/providers/elevenlabs.d.ts +1 -1
  26. package/dist/providers/elevenlabs.js +2 -7
  27. package/dist/providers/fireworks.d.ts +1 -1
  28. package/dist/providers/google/interactions.d.ts +1 -1
  29. package/dist/providers/google.d.ts +2 -2
  30. package/dist/providers/google.js +2 -7
  31. package/dist/providers/groq.d.ts +1 -1
  32. package/dist/providers/meta.d.ts +1 -1
  33. package/dist/providers/minimax.d.ts +1 -1
  34. package/dist/providers/mistral.d.ts +1 -1
  35. package/dist/providers/moonshot.d.ts +1 -1
  36. package/dist/providers/openai-compatible-responses.d.ts +1 -1
  37. package/dist/providers/openai-compatible.d.ts +1 -1
  38. package/dist/providers/openai.d.ts +1 -1
  39. package/dist/providers/opencode.d.ts +1 -1
  40. package/dist/providers/openrouter.d.ts +1 -1
  41. package/dist/providers/togetherai.d.ts +1 -1
  42. package/dist/providers/typesafe-ai.d.ts +1 -1
  43. package/dist/providers/venice.d.ts +1 -1
  44. package/dist/providers/vercel-ai-gateway.d.ts +1 -1
  45. package/dist/providers/xai.d.ts +1 -1
  46. package/dist/providers/zai-coding-plan.d.ts +1 -1
  47. package/dist/providers/zai.d.ts +1 -1
  48. package/dist/route/auth-options.d.ts +9 -5
  49. package/dist/route/auth-options.js +10 -7
  50. package/package.json +3 -3
package/README.md CHANGED
@@ -1476,6 +1476,8 @@ const gateway = CloudflareAIGateway.configure({
1476
1476
  }).model("workers-ai/@cf/meta/llama-3.1-8b-instruct")
1477
1477
  ```
1478
1478
 
1479
+ For a provider that needs no key, such as a local server, pass `apiKey: false`: the package skips the environment lookup and sends no auth header (Amazon Bedrock and Google Vertex keep their own auth).
1480
+
1479
1481
  Included LLM providers: OpenAI, Anthropic, Google (Gemini), Google Vertex, Amazon Bedrock (Converse and Mantle), Azure OpenAI, Alibaba, Baseten, Cerebras, Cohere, Cloudflare AI Gateway, Cloudflare Workers AI, DeepInfra, DeepSeek, DigitalOcean, Fireworks, Groq, Meta, MiniMax, Mistral, Moonshot, OpenRouter, TogetherAI, Venice, Vercel AI Gateway, xAI, Z.ai, and Z.ai Coding Plan. TypeSafe AI and OpenCode expose decision models only. Generic Chat Completions, Responses, and Anthropic Messages-compatible entrypoints support custom endpoints.
1480
1482
 
1481
1483
  Each named provider owns its module, endpoint, authentication, and route setup. Providers with the same wire format compose the shared protocol directly:
@@ -442,6 +442,12 @@ const mapContinuedUsage = (requests, metadataKey) => {
442
442
  requests: requests.length,
443
443
  });
444
444
  };
445
+ const terminalFinishReason = (finishReason) => finishReason && finishReason !== "FINISH_REASON_UNSPECIFIED" ? finishReason : undefined;
446
+ const RECOVERABLE_FINISH_REASONS = new Set([
447
+ "MALFORMED_RESPONSE",
448
+ "MALFORMED_FUNCTION_CALL",
449
+ "UNEXPECTED_TOOL_CALL",
450
+ ]);
445
451
  const mapFinishReason = (finishReason, hasToolCalls) => {
446
452
  if (finishReason === undefined)
447
453
  return hasToolCalls ? "tool-calls" : "unknown";
@@ -515,24 +521,22 @@ const step = (state, event) => {
515
521
  }));
516
522
  }
517
523
  const candidate = event.candidates?.[0];
524
+ const finishReason = terminalFinishReason(candidate?.finishReason);
518
525
  const nextState = {
519
526
  ...state,
520
527
  promptFeedback: event.promptFeedback ?? state.promptFeedback,
521
528
  usage: event.usageMetadata ?? state.usage,
522
- finishReason: candidate?.finishReason ?? state.finishReason,
529
+ finishReason: finishReason ?? state.finishReason,
523
530
  };
524
- // Gemini sporadically ends a valid request with MALFORMED_RESPONSE; continuing or resending it recovers.
525
- if (candidate?.finishReason === "MALFORMED_RESPONSE")
531
+ if (finishReason && mapFinishReason(finishReason, state.hasToolCalls) === "error")
526
532
  return Effect.fail(new AIError({
527
533
  reason: new InvalidProviderOutputError({
528
534
  route: state.route,
529
- message: `Gemini stopped with ${candidate.finishReason}`,
535
+ message: `Gemini stopped with ${finishReason}`,
530
536
  body: ProviderShared.encodeJson(event),
531
- classification: "incomplete-stream",
537
+ classification: RECOVERABLE_FINISH_REASONS.has(finishReason) ? "incomplete-stream" : undefined,
532
538
  }),
533
539
  }));
534
- if (candidate?.finishReason && mapFinishReason(candidate.finishReason, state.hasToolCalls) === "error")
535
- return Effect.fail(ProviderShared.eventError(state.route, `Gemini stopped with ${candidate.finishReason}`, ProviderShared.encodeJson(event)));
536
540
  if (!candidate?.content)
537
541
  return Effect.succeed([nextState, []]);
538
542
  const events = [];
@@ -692,8 +696,9 @@ export const transport = {
692
696
  if (typeof event === "object" && event !== null)
693
697
  raw.set(event, frame);
694
698
  const candidate = Option.getOrUndefined(decodeCheckpoint(event))?.candidates?.[0];
695
- token = candidate?.continuationToken ?? (candidate?.finishReason ? undefined : token);
696
- finishReason = candidate?.finishReason ?? finishReason;
699
+ const candidateFinishReason = terminalFinishReason(candidate?.finishReason);
700
+ token = candidate?.continuationToken ?? (candidateFinishReason ? undefined : token);
701
+ finishReason = candidateFinishReason ?? finishReason;
697
702
  return event;
698
703
  }))), Stream.catchIf(
699
704
  // A connection failure may resume; a timeout keeps its meaning and ends the response.
@@ -35,7 +35,6 @@ interface ParserState {
35
35
  readonly lifecycle: Lifecycle.State;
36
36
  readonly steps: Partial<Record<number, OutputStep>>;
37
37
  readonly tools: ToolStream.State<number>;
38
- readonly completed: boolean;
39
38
  }
40
39
  export declare const protocol: Protocol<{
41
40
  readonly model: string;
@@ -170,13 +169,18 @@ export declare const protocol: Protocol<{
170
169
  readonly message?: string | undefined;
171
170
  }[] | undefined;
172
171
  };
173
- } | {
174
- readonly event_type: "error";
175
- readonly error: unknown;
176
172
  } | {
177
173
  readonly event_type: "interaction.status_update";
178
174
  readonly interaction_id?: string | undefined;
179
175
  readonly status: string;
176
+ } | {
177
+ readonly event_type: "error";
178
+ readonly error?: {
179
+ readonly [x: string]: unknown;
180
+ readonly code?: string | undefined;
181
+ readonly error_type?: string | undefined;
182
+ readonly message?: string | undefined;
183
+ } | undefined;
180
184
  }, ParserState>;
181
185
  export declare const route: Route<{
182
186
  readonly model: string;
@@ -4,7 +4,7 @@ import { Auth } from "../route/auth.js";
4
4
  import { Endpoint } from "../route/endpoint.js";
5
5
  import { Framing } from "../route/framing.js";
6
6
  import { Protocol } from "../route/protocol.js";
7
- import { AIError, LLMEvent, ProviderID, Usage, } from "../schema/index.js";
7
+ import { AIError, ContentPolicyError, InvalidProviderOutputError, LLMEvent, ProviderID, Usage, } from "../schema/index.js";
8
8
  import { Media } from "../media.js";
9
9
  import { classifyProviderFailure, providerErrorMessage } from "../provider-error.js";
10
10
  import { encodeJson } from "../utils/json.js";
@@ -147,6 +147,11 @@ const UnknownEvent = Schema.Struct({
147
147
  decode: SchemaGetter.transform(() => ({ event_type: "unknown" })),
148
148
  encode: SchemaGetter.forbidden(() => "Unknown Google Interactions stream events are decode-only"),
149
149
  }));
150
+ const ErrorDetail = Schema.StructWithRest(Schema.Struct({
151
+ code: lenient(Schema.String),
152
+ error_type: lenient(Schema.String),
153
+ message: lenient(Schema.String),
154
+ }), [Schema.Record(Schema.String, Schema.Unknown)]);
150
155
  const Event = Schema.Union([
151
156
  Schema.Struct({ event_type: Schema.Literal("step.start"), index: Schema.Number, step: OutputStep }),
152
157
  Schema.Struct({ event_type: Schema.Literal("step.delta"), index: Schema.Number, delta: Delta }),
@@ -161,7 +166,7 @@ const Event = Schema.Union([
161
166
  status: Schema.String,
162
167
  }),
163
168
  Schema.Struct({ event_type: Schema.Literal("interaction.completed"), interaction: Interaction }),
164
- Schema.Struct({ event_type: Schema.Literal("error"), error: Schema.Unknown }),
169
+ Schema.Struct({ event_type: Schema.Literal("error"), error: lenient(ErrorDetail) }),
165
170
  UnknownEvent,
166
171
  ]);
167
172
  // =============================================================================
@@ -427,6 +432,23 @@ const onStop = Effect.fnUntraced(function* (state, index) {
427
432
  const result = yield* ToolStream.finish(ADAPTER, state.tools, index);
428
433
  return [{ ...state, tools: result.tools }, result.events ?? []];
429
434
  });
435
+ const RECOVERABLE_CODES = new Set([
436
+ "MALFORMED_FUNCTION_CALL",
437
+ "MALFORMED_TOOL_CALL",
438
+ "UNEXPECTED_TOOL_CALL",
439
+ "MALFORMED_RESPONSE",
440
+ ]);
441
+ const INVALID_OUTPUT_CODES = new Set(["MISSING_THOUGHT_SIGNATURE", "TOO_MANY_TOOL_CALLS", "NO_IMAGE"]);
442
+ const failureReason = (route, code, message, data, rawBody) => {
443
+ const normalized = code?.trim().toUpperCase().replaceAll("-", "_");
444
+ if (normalized && RECOVERABLE_CODES.has(normalized))
445
+ return new InvalidProviderOutputError({ route, message, body: rawBody, classification: "incomplete-stream" });
446
+ if (normalized && INVALID_OUTPUT_CODES.has(normalized))
447
+ return new InvalidProviderOutputError({ route, message, body: rawBody });
448
+ if (normalized && (normalized === "CONTENT_BLOCKED" || GeminiGenerateContent.contentFiltered(normalized)))
449
+ return new ContentPolicyError({ message, body: rawBody });
450
+ return classifyProviderFailure({ message, data, rawBody });
451
+ };
430
452
  const step = Effect.fnUntraced(function* (state, event) {
431
453
  switch (event.event_type) {
432
454
  case "step.start":
@@ -439,34 +461,31 @@ const step = Effect.fnUntraced(function* (state, event) {
439
461
  case "interaction.status_update":
440
462
  case "unknown":
441
463
  return [state, []];
442
- case "error":
464
+ case "error": {
465
+ const rawBody = encodeJson(event);
443
466
  return yield* new AIError({
444
- reason: classifyProviderFailure({
445
- message: providerErrorMessage(encodeJson(event)) ?? "Google Interactions stream error",
446
- data: event.error,
447
- rawBody: encodeJson(event),
448
- }),
467
+ reason: failureReason(state.route, event.error?.code ?? event.error?.error_type, event.error?.message?.trim() || providerErrorMessage(rawBody) || "Google Interactions stream error", event.error, rawBody),
449
468
  });
469
+ }
450
470
  case "interaction.completed": {
451
471
  const interaction = event.interaction;
452
472
  if (interaction.status === "failed" || interaction.status === "cancelled") {
453
473
  const messages = (interaction.errors ?? []).flatMap((error) => (error.message?.trim() ? [error.message] : []));
474
+ const coded = interaction.errors?.find((error) => error.code);
454
475
  return yield* new AIError({
455
- reason: classifyProviderFailure({
456
- message: messages.length > 0 ? messages.join("\n") : `Google Interactions ${interaction.status}`,
457
- // The first coded error decides the classification; every message stays visible.
458
- data: interaction.errors?.find((error) => error.code) ?? interaction,
459
- rawBody: encodeJson(event),
460
- }),
476
+ reason: failureReason(state.route, coded?.code, messages.length > 0 ? messages.join("\n") : `Google Interactions ${interaction.status}`,
477
+ // The first coded error decides the classification; every message stays visible.
478
+ coded ?? interaction, encodeJson(event)),
461
479
  });
462
480
  }
463
481
  if (!["completed", "requires_action", "incomplete"].includes(interaction.status))
464
482
  return yield* ProviderShared.eventError(ADAPTER, `Unexpected terminal Interactions status: ${interaction.status}`, encodeJson(event));
465
483
  const pending = yield* ToolStream.finishAll(ADAPTER, state.tools);
466
484
  const events = [...pending.events];
485
+ const hasToolCalls = Object.values(state.steps).some((item) => item?.type === "function_call");
467
486
  const lifecycle = Lifecycle.finish(state.lifecycle, events, {
468
487
  reason: {
469
- normalized: interaction.status === "requires_action"
488
+ normalized: interaction.status === "requires_action" || (interaction.status === "completed" && hasToolCalls)
470
489
  ? "tool-calls"
471
490
  : interaction.status === "incomplete"
472
491
  ? "length"
@@ -476,7 +495,7 @@ const step = Effect.fnUntraced(function* (state, event) {
476
495
  usage: mapUsage(interaction.usage, state.metadataKey),
477
496
  providerMetadata: { [state.metadataKey]: { interactionId: interaction.id } },
478
497
  });
479
- return [{ ...state, lifecycle, tools: pending.tools, completed: true }, events];
498
+ return [{ ...state, lifecycle, tools: pending.tools }, events];
480
499
  }
481
500
  }
482
501
  });
@@ -490,18 +509,14 @@ export const protocol = Protocol.make({
490
509
  stream: {
491
510
  event: Protocol.jsonEvent(Event),
492
511
  initial: (request) => ({
493
- route: `${request.model.provider}/${ADAPTER}`,
512
+ route: `${request.model.provider}/${request.model.route.id}`,
494
513
  metadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
495
514
  lifecycle: Lifecycle.initial(),
496
515
  steps: {},
497
516
  tools: ToolStream.empty(),
498
- completed: false,
499
517
  }),
500
518
  step,
501
519
  terminal: (event) => event.event_type === "interaction.completed",
502
- onHalt: (state) => state.completed
503
- ? Effect.succeed([])
504
- : Effect.fail(ProviderShared.eventError(ADAPTER, "Google Interactions stream ended before interaction.completed")),
505
520
  },
506
521
  });
507
522
  export const route = Route.make({
@@ -22,7 +22,7 @@ export type Config = Location & Omit<RouteDefaultsInput, "providerOptions"> & Pr
22
22
  readonly providerOptions?: ChatOptionsInput | MessagesOptionsInput | ResponsesOptionsInput;
23
23
  };
24
24
  export type Settings<Options = ChatOptionsInput> = Location & ProviderPackage.Settings & Options & {
25
- readonly apiKey?: string;
25
+ readonly apiKey?: string | false;
26
26
  };
27
27
  export declare const routes: (Route<{
28
28
  readonly model: string;
@@ -1,6 +1,6 @@
1
1
  import type { ProviderPackage } from "../provider-package.js";
2
2
  import { AnthropicMessages } from "../protocols/anthropic-messages.js";
3
- import type { ProviderAuthOption } from "../route/auth-options.js";
3
+ import { type ProviderAuthOption } from "../route/auth-options.js";
4
4
  import type { RouteDefaultsInput } from "../route/client.js";
5
5
  import { type ModelID } from "../schema/index.js";
6
6
  export type AnthropicOptionsInput = AnthropicMessages.OptionsInput;
@@ -13,7 +13,7 @@ export type Config = RouteDefaultsInput & ProviderAuthOption<"optional"> & {
13
13
  readonly providerOptions?: AnthropicMessages.ProviderOptionsInput;
14
14
  };
15
15
  export type Settings = ProviderPackage.Settings & AnthropicMessages.ProviderOptionsInput & ({
16
- readonly apiKey?: string;
16
+ readonly apiKey?: string | false;
17
17
  readonly authToken?: never;
18
18
  } | {
19
19
  readonly apiKey?: never;
@@ -1,14 +1,11 @@
1
1
  import { AnthropicMessages } from "../protocols/anthropic-messages.js";
2
2
  import { Auth } from "../route/auth.js";
3
+ import { AuthOptions } from "../route/auth-options.js";
3
4
  import { ProviderConfigurationError, ProviderID } from "../schema/index.js";
4
5
  export const id = ProviderID.make("anthropic-compatible");
5
6
  const compatibleRoute = AnthropicMessages.route.with({ id: "anthropic-compatible-messages", provider: id });
6
7
  export const routes = [compatibleRoute];
7
- const auth = (input) => {
8
- if ("auth" in input && input.auth)
9
- return input.auth;
10
- return Auth.optional("apiKey" in input ? input.apiKey : undefined, "apiKey").pipe(Auth.header("x-api-key"));
11
- };
8
+ const auth = (input) => AuthOptions.apiKey(input, [], Auth.header("x-api-key"));
12
9
  export const configure = (input) => {
13
10
  const provider = input.provider ?? "anthropic-compatible";
14
11
  if (!input.baseURL)
@@ -1,5 +1,5 @@
1
1
  import type { RouteDefaultsInput } from "../route/client.js";
2
- import type { ProviderAuthOption } from "../route/auth-options.js";
2
+ import { type ProviderAuthOption } from "../route/auth-options.js";
3
3
  import type { ProviderPackage } from "../provider-package.js";
4
4
  import { type ModelID } from "../schema/index.js";
5
5
  import { AnthropicMessages } from "../protocols/anthropic-messages.js";
@@ -320,7 +320,7 @@ export type Config = RouteDefaultsInput & ProviderAuthOption<"optional"> & {
320
320
  readonly providerOptions?: AnthropicMessages.ProviderOptionsInput;
321
321
  };
322
322
  export type Settings = ProviderPackage.Settings & AnthropicMessages.ProviderOptionsInput & ({
323
- readonly apiKey?: string;
323
+ readonly apiKey?: string | false;
324
324
  readonly authToken?: never;
325
325
  } | {
326
326
  readonly apiKey?: never;
@@ -1,16 +1,11 @@
1
1
  import { Auth } from "../route/auth.js";
2
+ import { AuthOptions } from "../route/auth-options.js";
2
3
  import { ProviderConfigurationError, ProviderID } from "../schema/index.js";
3
4
  import { AnthropicMessages } from "../protocols/anthropic-messages.js";
4
5
  import { AnthropicCompatible } from "./anthropic-compatible.js";
5
6
  export const id = ProviderID.make("anthropic");
6
7
  export const routes = [AnthropicMessages.route];
7
- const auth = (options) => {
8
- if ("auth" in options && options.auth)
9
- return options.auth;
10
- return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
11
- .orElse(Auth.config("ANTHROPIC_API_KEY"))
12
- .pipe(Auth.header("x-api-key"));
13
- };
8
+ const auth = (options) => AuthOptions.apiKey(options, "ANTHROPIC_API_KEY", Auth.header("x-api-key"));
14
9
  export const configure = (input = {}) => {
15
10
  const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
16
11
  const compatible = AnthropicCompatible.configure({
@@ -1,4 +1,4 @@
1
- import type { ProviderAuthOption } from "../route/auth-options.js";
1
+ import { type ProviderAuthOption } from "../route/auth-options.js";
2
2
  import { type HttpOptions, type ModelID } from "../schema/index.js";
3
3
  export type { AssemblyAITranscriptionOptions } from "../protocols/assemblyai-transcription.js";
4
4
  export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -1,16 +1,11 @@
1
1
  import { Auth } from "../route/auth.js";
2
+ import { AuthOptions } from "../route/auth-options.js";
2
3
  import { MediaRoute } from "../route/media.js";
3
4
  import { ProviderID } from "../schema/index.js";
4
5
  import { AssemblyAITranscription } from "../protocols/assemblyai-transcription.js";
5
6
  export const id = ProviderID.make("assemblyai");
6
7
  // The key is the whole `authorization` value, without a scheme.
7
- const auth = (options) => {
8
- if ("auth" in options && options.auth)
9
- return options.auth;
10
- return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
11
- .orElse(Auth.config("ASSEMBLYAI_API_KEY"))
12
- .pipe(Auth.header("authorization"));
13
- };
8
+ const auth = (options) => AuthOptions.apiKey(options, "ASSEMBLYAI_API_KEY", Auth.header("authorization"));
14
9
  export const configure = (input = {}) => {
15
10
  const media = MediaRoute.deployment(input, auth(input));
16
11
  const transcription = (modelID) => AssemblyAITranscription.model({ ...media, id: modelID });
@@ -15,7 +15,7 @@ export type Config = AzureURL & RouteDefaultsInput & ProviderAuthOption<"optiona
15
15
  readonly providerOptions?: OpenAIProviderOptionsInput;
16
16
  };
17
17
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & AzureURL & {
18
- readonly apiKey?: string;
18
+ readonly apiKey?: string | false;
19
19
  readonly apiVersion?: string;
20
20
  readonly queryParams?: Readonly<Record<string, string>>;
21
21
  readonly useDeploymentBasedUrls?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { Auth } from "../route/auth.js";
2
- import {} from "../route/auth-options.js";
2
+ import { AuthOptions } from "../route/auth-options.js";
3
3
  import { Endpoint } from "../route/endpoint.js";
4
4
  import { MediaRoute } from "../route/media.js";
5
5
  import { HttpOptions, ProviderConfigurationError, ProviderID, mergeHttpOptions, } from "../schema/index.js";
@@ -51,9 +51,7 @@ const defaults = (input) => {
51
51
  const auth = (input) => {
52
52
  if ("auth" in input && input.auth)
53
53
  return input.auth;
54
- return Auth.remove("authorization").andThen(Auth.optional("apiKey" in input ? input.apiKey : undefined, "apiKey")
55
- .orElse(Auth.config("AZURE_OPENAI_API_KEY"))
56
- .pipe(Auth.header("api-key")));
54
+ return Auth.remove("authorization").andThen(AuthOptions.apiKey(input, "AZURE_OPENAI_API_KEY", Auth.header("api-key")));
57
55
  };
58
56
  const configuredRoute = (route, input, modelID) => route.with({
59
57
  auth: auth(input),
@@ -13,7 +13,7 @@ export interface BasetenDecisionOptions {
13
13
  readonly max_len?: number;
14
14
  }
15
15
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
16
- readonly apiKey?: string;
16
+ readonly apiKey?: string | false;
17
17
  readonly baseURL?: string;
18
18
  };
19
19
  export declare const route: Route<{
@@ -9,7 +9,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
9
9
  readonly providerOptions?: OpenAIProviderOptionsInput;
10
10
  };
11
11
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
12
- readonly apiKey?: string;
12
+ readonly apiKey?: string | false;
13
13
  readonly baseURL?: string;
14
14
  };
15
15
  export declare const route: Route<{
@@ -1,6 +1,6 @@
1
1
  import type { Config, Redacted } from "effect";
2
2
  import type { ProviderPackage } from "../provider-package.js";
3
- import type { AtLeastOne, ProviderAuthOption } from "../route/auth-options.js";
3
+ import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js";
4
4
  import type { RouteDefaultsInput } from "../route/client.js";
5
5
  import { type ModelID, type ProviderOptions } from "../schema/index.js";
6
6
  import type { OpenAIProviderOptionsInput } from "./openai-options.js";
@@ -23,7 +23,7 @@ export type Config = GatewayURL & GatewayOptions & Omit<RouteDefaultsInput, "pro
23
23
  readonly providerOptions?: OpenAIProviderOptionsInput;
24
24
  };
25
25
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & GatewayURL & GatewayOptions & {
26
- readonly apiKey?: string;
26
+ readonly apiKey?: string | false;
27
27
  readonly gatewayApiKey?: string;
28
28
  };
29
29
  export declare const baseURL: (input: GatewayURL) => string;
@@ -2,6 +2,7 @@ import { CloudflareRunDecisions } from "../protocols/cloudflare-run-decisions.js
2
2
  import { AnthropicMessages, OpenAIChat, OpenAIResponses } from "../protocols/index.js";
3
3
  import { Auth } from "../route/auth.js";
4
4
  import { Endpoint } from "../route/endpoint.js";
5
+ import { AuthOptions } from "../route/auth-options.js";
5
6
  import { ProviderConfigurationError, ProviderID } from "../schema/index.js";
6
7
  import { encodeJson } from "../utils/json.js";
7
8
  export const id = ProviderID.make("cloudflare-ai-gateway");
@@ -49,9 +50,7 @@ export const route = OpenAIChat.route.with({
49
50
  endpoint: { baseURL: undefined },
50
51
  });
51
52
  export const routes = [responsesRoute, messagesRoute, route];
52
- const credential = (input) => Auth.optional(input.gatewayApiKey ?? ("apiKey" in input ? input.apiKey : undefined), "apiKey")
53
- .orElse(Auth.config(authEnvVars[0]))
54
- .orElse(Auth.config(authEnvVars[1]));
53
+ const credential = (input, apply) => AuthOptions.apiKey({ apiKey: input.gatewayApiKey ?? ("apiKey" in input ? input.apiKey : undefined) }, authEnvVars, apply);
55
54
  const headers = (input) => ({
56
55
  ...(input.metadata === undefined ? {} : { "cf-aig-metadata": encodeJson(input.metadata) }),
57
56
  ...(input.cacheTtl === undefined ? {} : { "cf-aig-cache-ttl": String(input.cacheTtl) }),
@@ -64,7 +63,7 @@ export const configure = (input) => {
64
63
  const custom = "auth" in input && input.auth ? input.auth : undefined;
65
64
  const rest = {
66
65
  endpoint: { baseURL: baseURL(input) },
67
- auth: custom ?? credential(input).bearer(),
66
+ auth: custom ?? credential(input, (credential) => credential.bearer()),
68
67
  headers: { "cf-aig-gateway-id": gatewayId(input), ...headers(input) },
69
68
  http: input.http,
70
69
  providerOptions: input.providerOptions,
@@ -75,7 +74,7 @@ export const configure = (input) => {
75
74
  ? {
76
75
  ...rest,
77
76
  endpoint: { baseURL: passthroughURL(input, provider) },
78
- auth: custom ?? Auth.bearerHeader("cf-aig-authorization", credential(input)),
77
+ auth: custom ?? credential(input, Auth.bearerHeader("cf-aig-authorization")),
79
78
  headers: headers(input),
80
79
  }
81
80
  : rest;
@@ -13,7 +13,7 @@ export type Config = WorkersAIURL & Omit<RouteDefaultsInput, "providerOptions">
13
13
  readonly providerOptions?: OpenAIProviderOptionsInput;
14
14
  };
15
15
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & WorkersAIURL & {
16
- readonly apiKey?: string;
16
+ readonly apiKey?: string | false;
17
17
  };
18
18
  export type { CloudflareWorkersAIImageOptions } from "../protocols/cloudflare-workers-ai-images.js";
19
19
  export declare const baseURL: (input: WorkersAIURL) => string;
@@ -13,7 +13,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
13
13
  readonly providerOptions?: ProviderOptions;
14
14
  };
15
15
  export type Settings<Options = CohereChat.ProviderOptionsInput> = ProviderPackage.Settings & Options & {
16
- readonly apiKey?: string;
16
+ readonly apiKey?: string | false;
17
17
  readonly baseURL?: string;
18
18
  };
19
19
  export declare const route: Route<{
@@ -1,4 +1,4 @@
1
- import type { ProviderAuthOption } from "../route/auth-options.js";
1
+ import { type ProviderAuthOption } from "../route/auth-options.js";
2
2
  import { type HttpOptions, type ModelID } from "../schema/index.js";
3
3
  export type { DeepgramEncoding, DeepgramSpeechOptions } from "../protocols/deepgram-speech.js";
4
4
  export type { DeepgramTranscriptionOptions } from "../protocols/deepgram-transcription.js";
@@ -1,16 +1,11 @@
1
1
  import { Auth } from "../route/auth.js";
2
+ import { AuthOptions } from "../route/auth-options.js";
2
3
  import { MediaRoute } from "../route/media.js";
3
4
  import { ProviderID } from "../schema/index.js";
4
5
  import { DeepgramSpeech } from "../protocols/deepgram-speech.js";
5
6
  import { DeepgramTranscription } from "../protocols/deepgram-transcription.js";
6
7
  export const id = ProviderID.make("deepgram");
7
- const auth = (options) => {
8
- if ("auth" in options && options.auth)
9
- return options.auth;
10
- return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
11
- .orElse(Auth.config("DEEPGRAM_API_KEY"))
12
- .pipe(Auth.scheme("Token"));
13
- };
8
+ const auth = (options) => AuthOptions.apiKey(options, "DEEPGRAM_API_KEY", Auth.scheme("Token"));
14
9
  export const configure = (input = {}) => {
15
10
  const media = MediaRoute.deployment(input, auth(input));
16
11
  return {
@@ -9,7 +9,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
9
9
  readonly providerOptions?: OpenAIProviderOptionsInput;
10
10
  };
11
11
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
12
- readonly apiKey?: string;
12
+ readonly apiKey?: string | false;
13
13
  readonly baseURL?: string;
14
14
  };
15
15
  export declare const route: Route<{
@@ -9,7 +9,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
9
9
  readonly providerOptions?: OpenAIProviderOptionsInput;
10
10
  };
11
11
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
12
- readonly apiKey?: string;
12
+ readonly apiKey?: string | false;
13
13
  readonly baseURL?: string;
14
14
  };
15
15
  export declare const route: Route<{
@@ -12,7 +12,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
12
12
  readonly providerOptions?: OpenAIProviderOptionsInput | OpenResponsesProviderOptionsInput;
13
13
  };
14
14
  export type Settings<Options = OpenAIProviderOptionsInput> = ProviderPackage.Settings & Options & {
15
- readonly apiKey?: string;
15
+ readonly apiKey?: string | false;
16
16
  };
17
17
  export declare const protocol: Protocol<{
18
18
  readonly model: string;
@@ -1,4 +1,4 @@
1
- import type { ProviderAuthOption } from "../route/auth-options.js";
1
+ import { type ProviderAuthOption } from "../route/auth-options.js";
2
2
  import { type HttpOptions, type ModelID } from "../schema/index.js";
3
3
  export type { ElevenLabsOutputFormat, ElevenLabsSpeechOptions } from "../protocols/elevenlabs-speech.js";
4
4
  export type { ElevenLabsTranscriptionOptions } from "../protocols/elevenlabs-transcription.js";
@@ -1,16 +1,11 @@
1
1
  import { Auth } from "../route/auth.js";
2
+ import { AuthOptions } from "../route/auth-options.js";
2
3
  import { MediaRoute } from "../route/media.js";
3
4
  import { ProviderID } from "../schema/index.js";
4
5
  import { ElevenLabsSpeech } from "../protocols/elevenlabs-speech.js";
5
6
  import { ElevenLabsTranscription } from "../protocols/elevenlabs-transcription.js";
6
7
  export const id = ProviderID.make("elevenlabs");
7
- const auth = (options) => {
8
- if ("auth" in options && options.auth)
9
- return options.auth;
10
- return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
11
- .orElse(Auth.config("ELEVENLABS_API_KEY"))
12
- .pipe(Auth.header("xi-api-key"));
13
- };
8
+ const auth = (options) => AuthOptions.apiKey(options, "ELEVENLABS_API_KEY", Auth.header("xi-api-key"));
14
9
  export const configure = (input = {}) => {
15
10
  const media = MediaRoute.deployment(input, auth(input));
16
11
  const speech = (modelID) => ElevenLabsSpeech.model({ ...media, id: modelID });
@@ -9,7 +9,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
9
9
  readonly providerOptions?: OpenAIProviderOptionsInput;
10
10
  };
11
11
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
12
- readonly apiKey?: string;
12
+ readonly apiKey?: string | false;
13
13
  readonly baseURL?: string;
14
14
  };
15
15
  export declare const route: Route<{
@@ -1,7 +1,7 @@
1
1
  import type { ProviderPackage } from "../../provider-package.js";
2
2
  import type { GoogleInteractions } from "../../protocols/google-interactions.js";
3
3
  export type Settings = ProviderPackage.Settings & GoogleInteractions.ProviderOptionsInput & {
4
- readonly apiKey?: string;
4
+ readonly apiKey?: string | false;
5
5
  readonly baseURL?: string;
6
6
  };
7
7
  export declare const model: ProviderPackage.Model<Settings, GoogleInteractions.ProviderOptionsInput>;
@@ -1,5 +1,5 @@
1
1
  import type { RouteDefaultsInput } from "../route/client.js";
2
- import type { ProviderAuthOption } from "../route/auth-options.js";
2
+ import { type ProviderAuthOption } from "../route/auth-options.js";
3
3
  import type { ProviderPackage } from "../provider-package.js";
4
4
  import { type ModelID, type ProviderOptions } from "../schema/index.js";
5
5
  import { Gemini } from "../protocols/gemini.js";
@@ -164,7 +164,7 @@ export type Config = RouteDefaultsInput & ProviderAuthOption<"optional"> & {
164
164
  readonly providerOptions?: Gemini.ProviderOptionsInput & GoogleInteractions.ProviderOptionsInput;
165
165
  };
166
166
  export type Settings = ProviderPackage.Settings & Gemini.ProviderOptionsInput & {
167
- readonly apiKey?: string;
167
+ readonly apiKey?: string | false;
168
168
  readonly baseURL?: string;
169
169
  };
170
170
  export declare const configure: (input?: Config) => {
@@ -1,4 +1,5 @@
1
1
  import { Auth } from "../route/auth.js";
2
+ import { AuthOptions } from "../route/auth-options.js";
2
3
  import { MediaRoute } from "../route/media.js";
3
4
  import { ProviderID } from "../schema/index.js";
4
5
  import { Gemini } from "../protocols/gemini.js";
@@ -9,13 +10,7 @@ import { GoogleTranscription } from "../protocols/google-transcription.js";
9
10
  import { GoogleVideo } from "../protocols/google-video.js";
10
11
  export const id = ProviderID.make("google");
11
12
  export const routes = [Gemini.route, GoogleInteractions.route];
12
- const auth = (options) => {
13
- if ("auth" in options && options.auth)
14
- return options.auth;
15
- return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
16
- .orElse(Auth.config("GOOGLE_GENERATIVE_AI_API_KEY"))
17
- .pipe(Auth.header("x-goog-api-key"));
18
- };
13
+ const auth = (options) => AuthOptions.apiKey(options, "GOOGLE_GENERATIVE_AI_API_KEY", Auth.header("x-goog-api-key"));
19
14
  const configuredRoute = (input) => {
20
15
  const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
21
16
  return Gemini.route.with({ ...rest, endpoint: { baseURL }, auth: auth(input) });
@@ -18,7 +18,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
18
18
  readonly providerOptions?: ProviderOptions;
19
19
  };
20
20
  export type Settings = ProviderPackage.Settings & ProviderOptions & {
21
- readonly apiKey?: string;
21
+ readonly apiKey?: string | false;
22
22
  readonly baseURL?: string;
23
23
  };
24
24
  export declare const protocol: Protocol<{
@@ -35,7 +35,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
35
35
  readonly providerOptions?: ProviderOptionsInput;
36
36
  };
37
37
  export type Settings = ProviderPackage.Settings & ProviderOptionsInput & {
38
- readonly apiKey?: string;
38
+ readonly apiKey?: string | false;
39
39
  readonly baseURL?: string;
40
40
  };
41
41
  export declare const routes: (Route<{
@@ -31,7 +31,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
31
31
  readonly providerOptions?: ProviderOptionsInput;
32
32
  };
33
33
  export type Settings<Options = MessagesOptionsInput> = ProviderPackage.Settings & Options & {
34
- readonly apiKey?: string;
34
+ readonly apiKey?: string | false;
35
35
  readonly baseURL?: string;
36
36
  };
37
37
  export type { MiniMaxImageOptions };
@@ -10,7 +10,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
10
10
  readonly providerOptions?: ProviderOptions;
11
11
  };
12
12
  export type Settings = ProviderPackage.Settings & ProviderOptions & {
13
- readonly apiKey?: string;
13
+ readonly apiKey?: string | false;
14
14
  readonly baseURL?: string;
15
15
  };
16
16
  export declare const route: import("../route/client.js").Route<{
@@ -28,7 +28,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
28
28
  readonly providerOptions?: ChatOptionsInput | MessagesOptionsInput | ResponsesOptionsInput;
29
29
  };
30
30
  export type Settings<Options = ChatOptionsInput> = ProviderPackage.Settings & Options & {
31
- readonly apiKey?: string;
31
+ readonly apiKey?: string | false;
32
32
  readonly baseURL?: string;
33
33
  };
34
34
  export declare const routes: (Route<{
@@ -11,7 +11,7 @@ export type Config = RouteDefaultsInput & ProviderAuthOption<"optional"> & {
11
11
  readonly providerOptions?: OpenResponsesProviderOptionsInput;
12
12
  };
13
13
  export type Settings = ProviderPackage.Settings & OpenResponsesProviderOptionsInput & {
14
- readonly apiKey?: string;
14
+ readonly apiKey?: string | false;
15
15
  readonly baseURL: string;
16
16
  readonly provider?: string;
17
17
  };
@@ -10,7 +10,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
10
10
  readonly providerOptions?: OpenAIProviderOptionsInput;
11
11
  };
12
12
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
13
- readonly apiKey?: string;
13
+ readonly apiKey?: string | false;
14
14
  readonly baseURL: string;
15
15
  readonly provider?: string;
16
16
  };
@@ -434,7 +434,7 @@ export interface ImageGenerationOptions {
434
434
  }
435
435
  export declare const imageGeneration: (options?: ImageGenerationOptions) => ToolDefinition;
436
436
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
437
- readonly apiKey?: string;
437
+ readonly apiKey?: string | false;
438
438
  readonly baseURL?: string;
439
439
  readonly organization?: string;
440
440
  readonly project?: string;
@@ -8,7 +8,7 @@ export type Config = ProviderAuthOption<"optional"> & {
8
8
  readonly http?: HttpOptions.Input;
9
9
  };
10
10
  export type Settings = ProviderPackage.Settings & {
11
- readonly apiKey?: string;
11
+ readonly apiKey?: string | false;
12
12
  };
13
13
  export declare const configure: (input?: Config) => {
14
14
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -87,7 +87,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
87
87
  readonly providerOptions?: OpenRouterProviderOptionsInput | OpenRouterResponsesProviderOptionsInput;
88
88
  };
89
89
  export type Settings<Options = OpenRouterProviderOptionsInput> = ProviderPackage.Settings & Options & {
90
- readonly apiKey?: string;
90
+ readonly apiKey?: string | false;
91
91
  readonly baseURL?: string;
92
92
  };
93
93
  declare const OpenRouterBody: Schema.StructWithRest<Schema.Struct<{
@@ -9,7 +9,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
9
9
  readonly providerOptions?: OpenAIProviderOptionsInput;
10
10
  };
11
11
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
12
- readonly apiKey?: string;
12
+ readonly apiKey?: string | false;
13
13
  readonly baseURL?: string;
14
14
  };
15
15
  export declare const route: Route<{
@@ -8,7 +8,7 @@ export type Config = ProviderAuthOption<"optional"> & {
8
8
  readonly http?: HttpOptions.Input;
9
9
  };
10
10
  export type Settings = ProviderPackage.Settings & {
11
- readonly apiKey?: string;
11
+ readonly apiKey?: string | false;
12
12
  };
13
13
  export declare const configure: (input?: Config) => {
14
14
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -12,7 +12,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
12
12
  readonly providerOptions?: ChatOptionsInput | OpenResponsesProviderOptionsInput;
13
13
  };
14
14
  export type Settings<Options = ChatOptionsInput> = ProviderPackage.Settings & Options & {
15
- readonly apiKey?: string;
15
+ readonly apiKey?: string | false;
16
16
  readonly baseURL?: string;
17
17
  readonly queryParams?: Readonly<Record<string, string>>;
18
18
  };
@@ -68,7 +68,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
68
68
  readonly providerOptions?: ProviderOptionsInput;
69
69
  };
70
70
  export type Settings = ProviderPackage.Settings & ProviderOptionsInput & {
71
- readonly apiKey?: string;
71
+ readonly apiKey?: string | false;
72
72
  };
73
73
  export declare const routes: Route<{
74
74
  readonly [x: string]: unknown;
@@ -13,7 +13,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
13
13
  readonly providerOptions?: XAIProviderOptionsInput;
14
14
  };
15
15
  export type Settings = ProviderPackage.Settings & XAIProviderOptionsInput & {
16
- readonly apiKey?: string;
16
+ readonly apiKey?: string | false;
17
17
  readonly baseURL?: string;
18
18
  };
19
19
  export type { XAIImageOptions } from "../protocols/xai-images.js";
@@ -16,7 +16,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
16
16
  readonly providerOptions?: ChatOptionsInput | MessagesOptionsInput | ResponsesOptionsInput;
17
17
  };
18
18
  export type Settings<Options = ChatOptionsInput> = ProviderPackage.Settings & Options & {
19
- readonly apiKey?: string;
19
+ readonly apiKey?: string | false;
20
20
  readonly baseURL?: string;
21
21
  };
22
22
  export declare const routes: (Route<{
@@ -10,7 +10,7 @@ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthO
10
10
  readonly providerOptions?: ChatOptionsInput;
11
11
  };
12
12
  export type Settings = ProviderPackage.Settings & ChatOptionsInput & {
13
- readonly apiKey?: string;
13
+ readonly apiKey?: string | false;
14
14
  readonly baseURL?: string;
15
15
  };
16
16
  export type { ZAIImageOptions } from "../protocols/zai-images.js";
@@ -5,12 +5,14 @@ export type AuthOverride = {
5
5
  readonly auth: Auth.Definition;
6
6
  readonly apiKey?: never;
7
7
  };
8
+ /** `false` marks a provider that needs no key: no env lookup and no auth header from the package. */
9
+ export type ApiKey = string | Redacted.Redacted<string> | Config.Config<string | Redacted.Redacted<string>> | false;
8
10
  export type OptionalApiKeyAuth = {
9
- readonly apiKey?: string | Redacted.Redacted<string> | Config.Config<string | Redacted.Redacted<string>>;
11
+ readonly apiKey?: ApiKey;
10
12
  readonly auth?: never;
11
13
  };
12
14
  export type RequiredApiKeyAuth = {
13
- readonly apiKey: string | Redacted.Redacted<string> | Config.Config<string | Redacted.Redacted<string>>;
15
+ readonly apiKey: ApiKey;
14
16
  readonly auth?: never;
15
17
  };
16
18
  export type ProviderAuthOption<Mode extends ApiKeyMode> = AuthOverride | (Mode extends "optional" ? OptionalApiKeyAuth : RequiredApiKeyAuth);
@@ -23,9 +25,11 @@ export type AtLeastOne<T> = {
23
25
  [K in keyof T]: Required<Pick<T, K>> & Partial<Omit<T, K>>;
24
26
  }[keyof T];
25
27
  /**
26
- * Standard bearer-auth resolution for providers: honor an explicit `auth`
27
- * override, otherwise resolve `apiKey` (option > config var) and apply it as
28
- * a bearer token.
28
+ * Standard API-key resolution for providers: honor an explicit `auth`
29
+ * override, skip auth entirely for `apiKey: false`, otherwise resolve `apiKey`
30
+ * (option > config vars) and render it with `apply`.
29
31
  */
32
+ export declare const apiKey: (options: ProviderAuthOption<"optional">, envVar: string | ReadonlyArray<string>, apply: (credential: Auth.Credential) => Auth.Definition) => Auth.Definition;
33
+ /** `apiKey` resolution applied as `Authorization: Bearer <key>`. */
30
34
  export declare const bearer: (options: ProviderAuthOption<"optional">, envVar: string | ReadonlyArray<string>) => Auth.Definition;
31
35
  export * as AuthOptions from "./auth-options.js";
@@ -1,14 +1,17 @@
1
1
  import { Auth } from "./auth.js";
2
2
  /**
3
- * Standard bearer-auth resolution for providers: honor an explicit `auth`
4
- * override, otherwise resolve `apiKey` (option > config var) and apply it as
5
- * a bearer token.
3
+ * Standard API-key resolution for providers: honor an explicit `auth`
4
+ * override, skip auth entirely for `apiKey: false`, otherwise resolve `apiKey`
5
+ * (option > config vars) and render it with `apply`.
6
6
  */
7
- export const bearer = (options, envVar) => {
7
+ export const apiKey = (options, envVar, apply) => {
8
8
  if ("auth" in options && options.auth)
9
9
  return options.auth;
10
- return (Array.isArray(envVar) ? envVar : [envVar])
11
- .reduce((auth, name) => auth.orElse(Auth.config(name)), Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey"))
12
- .bearer();
10
+ const key = "apiKey" in options ? options.apiKey : undefined;
11
+ if (key === false)
12
+ return Auth.none;
13
+ return apply((Array.isArray(envVar) ? envVar : [envVar]).reduce((auth, name) => auth.orElse(Auth.config(name)), Auth.optional(key, "apiKey")));
13
14
  };
15
+ /** `apiKey` resolution applied as `Authorization: Bearer <key>`. */
16
+ export const bearer = (options, envVar) => apiKey(options, envVar, (credential) => credential.bearer());
14
17
  export * as AuthOptions from "./auth-options.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-414",
3
+ "version": "0.0.0-dev-420",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -520,7 +520,7 @@
520
520
  "devDependencies": {
521
521
  "@clack/prompts": "1.0.0-alpha.1",
522
522
  "@effect/platform-node": "4.0.6",
523
- "@opencode/http-recorder": "0.0.0-dev-414",
523
+ "@opencode/http-recorder": "0.0.0-dev-420",
524
524
  "@tsconfig/bun": "1.0.9",
525
525
  "@types/bun": "1.4.3",
526
526
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -530,7 +530,7 @@
530
530
  "@aws-sdk/credential-providers": "3.1057.0",
531
531
  "@smithy/eventstream-codec": "4.2.14",
532
532
  "@smithy/util-utf8": "4.2.2",
533
- "@opencode/schema": "0.0.0-dev-414",
533
+ "@opencode/schema": "0.0.0-dev-420",
534
534
  "aws4fetch": "1.0.20",
535
535
  "effect": "4.0.6",
536
536
  "google-auth-library": "10.5.0"