diff --git a/packages/ai/README.md b/packages/ai/README.md index 25668ddc34d9..f73e523c9c33 100644 --- a/packages/ai/README.md +++ b/packages/ai/README.md @@ -69,6 +69,12 @@ const program = Effect.gen(function* () { await Effect.runPromise(program.pipe(Effect.provide(AI.fetchLayer))) ``` +Credentials belong to the provider: `openai({ apiKey })` makes one credential that every model from that provider +shares as `model.auth`, and the model's API decides how it is sent (header and prefix). Without `apiKey`, the +provider's environment variables (`OPENAI_API_KEY`) are read when each request is sent; `apiKey: false` sends none. A +request's own `apiKey` wins over the provider's. Keys are kept as a `Secret`, which prints as `""` from +`String`, `JSON.stringify` and `console.log`; `Secret.value(secret)` reads one. + Run `ai.stream(...)` instead of `generate` when you want incremental `StreamEvent`s. Both accept input or a prebuilt `ai.request(...)`. Input takes either `prompt`, a single user message, or `messages`, the whole conversation, never both; `system` goes with either. The event stream is provider-neutral — same shape across OpenAI Chat, OpenAI Responses, diff --git a/packages/ai/src/auth-source.ts b/packages/ai/src/auth-source.ts new file mode 100644 index 000000000000..49583e2cedb0 --- /dev/null +++ b/packages/ai/src/auth-source.ts @@ -0,0 +1,34 @@ +import type { Auth } from "./route/auth.js" +import type { Secret } from "./secret.js" + +// Package-private: a custom source keeps its signing, OAuth or bearer handler behind this key, out of public types. +const HANDLER = Symbol("opencode.ai.auth") + +/** + * Where a provider's credential comes from, as plain data. A provider makes one when it is called and every model it + * builds shares it; the API decides how a key is sent. Environment variables are read when a request is sent. + * `custom` is a handler the provider owns: Bedrock SigV4, Vertex access tokens and OAuth, bearer tokens. + */ +export type AuthSource = + | { readonly type: "env"; readonly vars: ReadonlyArray } + | { readonly type: "key"; readonly key: Secret } + | { readonly type: "none" } + | { readonly type: "custom" } + +/** A source whose handler signs or authorizes each request itself. */ +export const custom = (handler: Auth.Definition): AuthSource => { + const source = { type: "custom" as const, [HANDLER]: handler } + return source +} + +/** The handler behind a custom source. */ +export const handlerOf = (source: AuthSource): Auth.Definition | undefined => + isCustom(source) ? source[HANDLER] : undefined + +const isCustom = (source: object): source is { readonly [HANDLER]: Auth.Definition } => HANDLER in source + +/** What an API's own auth implies without a key: its environment variables, or its handler. */ +export const sourceOf = (auth: Auth.Authentication | undefined): AuthSource => { + if (auth === undefined) return { type: "none" } + return "type" in auth ? { type: "env", vars: auth.env } : custom(auth) +} diff --git a/packages/ai/src/decision-client.ts b/packages/ai/src/decision-client.ts index 1b7a51872a7e..7524eb81c8c3 100644 --- a/packages/ai/src/decision-client.ts +++ b/packages/ai/src/decision-client.ts @@ -25,7 +25,7 @@ export interface Interface { export const make = (execute: Execute): Interface => ({ generate: Effect.fnUntraced(function* (request) { - const route = jsonRouteOf(request.model, internal(request.model.api)) + const route = jsonRouteOf(request, internal(request.model.api)) const input = internal(request.model.api).protocol.inlineMedia ? yield* Effect.forEach(request.input, (part) => materialize( diff --git a/packages/ai/src/embedding-client.ts b/packages/ai/src/embedding-client.ts index 5aca7e103325..0081505313e4 100644 --- a/packages/ai/src/embedding-client.ts +++ b/packages/ai/src/embedding-client.ts @@ -17,7 +17,7 @@ export interface Interface { export const make = (execute: Execute): Interface => ({ generate: Effect.fnUntraced(function* (request) { - const route = jsonRouteOf(request.model, internal(request.model.api)) + const route = jsonRouteOf(request, internal(request.model.api)) const response = yield* split(Api.maxValues(internal(request.model.api).maxValues, request.model.id), (part) => route.generate(part, execute), )(request) diff --git a/packages/ai/src/generation.ts b/packages/ai/src/generation.ts index 8b1ab114026b..cb27d874ed7a 100644 --- a/packages/ai/src/generation.ts +++ b/packages/ai/src/generation.ts @@ -1,5 +1,11 @@ import { Clock, Duration, Effect, Schedule, Schema, Stream } from "effect" import { AIError, TimeoutError } from "./schema/errors.js" +import type { Secret } from "./secret.js" + +/** Options of a job call by ID (`status`, `result`, `cancel`): the call's own API key wins over the provider's. */ +export interface JobOptions { + readonly apiKey?: string | Secret +} /** Why a generation ended in `error`. */ export const Reason = Schema.Literals(["failed", "cancelled", "expired"]) diff --git a/packages/ai/src/image.ts b/packages/ai/src/image.ts index 70e10264be4b..f79d578bd5cd 100644 --- a/packages/ai/src/image.ts +++ b/packages/ai/src/image.ts @@ -1,5 +1,5 @@ import { Effect, Schema, Stream } from "effect" -import { ProgressEvent, type AwaitOptions, type Job, type Status } from "./generation.js" +import { ProgressEvent, type AwaitOptions, type Job, type JobOptions, type Status } from "./generation.js" import { Media } from "./media.js" import { requestParser } from "./media-model.js" import { isModel, type Model } from "./model.js" @@ -160,16 +160,22 @@ export function start(input: ImageRequestInput) { } /** One status read for a job ID. */ -export const status = (model: ImageModel, id: string): Effect.Effect => - AI.Service.use((ai) => ai.image.status(model, id)) - -/** The finished images; fails while the job is still running, or with the provider's reason when it failed. */ -export const result = (model: ImageModel, id: string): Effect.Effect => - AI.Service.use((ai) => ai.image.result(model, id)) +export const status = ( + model: ImageModel, + id: string, + options?: JobOptions, +): Effect.Effect => AI.Service.use((ai) => ai.image.status(model, id, options)) + +/** The finished result; fails while the job is still running, or with the provider's reason when it failed. */ +export const result = ( + model: ImageModel, + id: string, + options?: JobOptions, +): Effect.Effect => AI.Service.use((ai) => ai.image.result(model, id, options)) /** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */ -export const cancel = (model: ImageModel, id: string): Effect.Effect => - AI.Service.use((ai) => ai.image.cancel(model, id)) +export const cancel = (model: ImageModel, id: string, options?: JobOptions): Effect.Effect => + AI.Service.use((ai) => ai.image.cancel(model, id, options)) export const Image = { request, diff --git a/packages/ai/src/index.ts b/packages/ai/src/index.ts index 4285485e37b0..e3ffa5eaf22a 100644 --- a/packages/ai/src/index.ts +++ b/packages/ai/src/index.ts @@ -3,6 +3,7 @@ import { layerWith, type Services } from "./ai.js" import { Decision, type DecisionModel, type DecisionQuestions, type DecisionRequestInput } from "./decision.js" import { Embedding, type EmbeddingModel, type EmbeddingRequestInput } from "./embedding.js" import { type FetchMiddleware, fromFetch } from "./fetch-middleware.js" +import type { JobOptions } from "./generation.js" import { Image, type ImageModel, type ImageRequest, type ImageRequestInput } from "./image.js" import { Media } from "./promise-media.js" import { @@ -299,10 +300,13 @@ const make = (options: ClientOptions = {}) => { start: (input: ImageRequestInput | ImageRequest, options?: RunOptions) => run(Image.start(input), options), /** One status read for a job ID. */ - status: (model: ImageModel, id: string, options?: RunOptions) => run(Image.status(model, id), options), + status: (model: ImageModel, id: string, options?: RunOptions & JobOptions) => + run(Image.status(model, id, options), options), /** The finished images; fails while the job is still running. */ - result: (model: ImageModel, id: string, options?: RunOptions) => run(Image.result(model, id), options), - cancel: (model: ImageModel, id: string, options?: RunOptions) => run(Image.cancel(model, id), options), + result: (model: ImageModel, id: string, options?: RunOptions & JobOptions) => + run(Image.result(model, id, options), options), + cancel: (model: ImageModel, id: string, options?: RunOptions & JobOptions) => + run(Image.cancel(model, id, options), options), }, decision: { request: Decision.request, @@ -332,10 +336,13 @@ const make = (options: ClientOptions = {}) => { start: (input: VideoRequestInput | VideoRequest, options?: RunOptions) => run(Video.start(input), options), /** One status read for a job ID. */ - status: (model: VideoModel, id: string, options?: RunOptions) => run(Video.status(model, id), options), + status: (model: VideoModel, id: string, options?: RunOptions & JobOptions) => + run(Video.status(model, id, options), options), /** The finished videos; fails while the job is still running. */ - result: (model: VideoModel, id: string, options?: RunOptions) => run(Video.result(model, id), options), - cancel: (model: VideoModel, id: string, options?: RunOptions) => run(Video.cancel(model, id), options), + result: (model: VideoModel, id: string, options?: RunOptions & JobOptions) => + run(Video.result(model, id, options), options), + cancel: (model: VideoModel, id: string, options?: RunOptions & JobOptions) => + run(Video.cancel(model, id, options), options), }, speech: { request: Speech.request, @@ -364,13 +371,13 @@ const make = (options: ClientOptions = {}) => { options?: RunOptions, ) => run(Transcription.start(input), options), /** One status read for a job ID. */ - status: (model: TranscriptionModel, id: string, options?: RunOptions) => - run(Transcription.status(model, id), options), + status: (model: TranscriptionModel, id: string, options?: RunOptions & JobOptions) => + run(Transcription.status(model, id, options), options), /** The finished transcript; fails while the job is still running. */ - result: (model: TranscriptionModel, id: string, options?: RunOptions) => - run(Transcription.result(model, id), options), - cancel: (model: TranscriptionModel, id: string, options?: RunOptions) => - run(Transcription.cancel(model, id), options), + result: (model: TranscriptionModel, id: string, options?: RunOptions & JobOptions) => + run(Transcription.result(model, id, options), options), + cancel: (model: TranscriptionModel, id: string, options?: RunOptions & JobOptions) => + run(Transcription.cancel(model, id, options), options), }, dispose: () => runtime.dispose(), } diff --git a/packages/ai/src/media-client.ts b/packages/ai/src/media-client.ts index a1d56d81f3da..81dc4f42f396 100644 --- a/packages/ai/src/media-client.ts +++ b/packages/ai/src/media-client.ts @@ -1,5 +1,13 @@ import { Effect, Stream } from "effect" -import { resultEvents, wait, type AwaitOptions, type Job, type Observation, type Status } from "./generation.js" +import { + resultEvents, + wait, + type AwaitOptions, + type Job, + type JobOptions, + type Observation, + type Status, +} from "./generation.js" import type { Api } from "./api.js" import { routeOf } from "./media-model.js" import type { Model } from "./model.js" @@ -16,9 +24,9 @@ export interface Interface { readonly generate: (request: Req, options?: AwaitOptions) => Effect.Effect readonly stream: (request: Req, options?: AwaitOptions) => Stream.Stream readonly start: (request: Req) => Effect.Effect - readonly status: (model: Req["model"], id: string) => Effect.Effect - readonly result: (model: Req["model"], id: string) => Effect.Effect - readonly cancel: (model: Req["model"], id: string) => Effect.Effect + readonly status: (model: Req["model"], id: string, options?: JobOptions) => Effect.Effect + readonly result: (model: Req["model"], id: string, options?: JobOptions) => Effect.Effect + readonly cancel: (model: Req["model"], id: string, options?: JobOptions) => Effect.Effect } export interface Input { @@ -49,26 +57,27 @@ export const operations = ( execute: MediaRoute.Execute, input: Input, ): Interface => { - const routeFor = (model: Req["model"]) => routeOf(model, input.collect) + const routeFor = (model: Req["model"], apiKey?: Req["apiKey"]) => + routeOf(model, input.collect, apiKey) const start = (request: Req) => { - const route = routeFor(request.model) + const route = routeFor(request.model, request.apiKey) if (route.kind !== "queued") return Effect.fail(notQueued(input.modality, route, "start")) return route.start(request, execute) } const generation = `${/^[aeiou]/.test(input.modality) ? "an" : "a"} ${input.modality} generation` - const attach = (model: Req["model"], id: string, operation: string) => { - const route = routeFor(model) + const attach = (model: Req["model"], id: string, operation: string, options: JobOptions | undefined) => { + const route = routeFor(model, options?.apiKey) if (route.kind !== "queued") return Effect.fail(notQueued(input.modality, route, operation)) return route.attach(model, id, execute) } return { generate: (request, options) => { - const route = routeFor(request.model) + const route = routeFor(request.model, request.apiKey) if (route.kind !== "queued") return route.generate(request, execute) return start(request).pipe(Effect.flatMap((started) => wait(started, options))) }, stream: (request, options) => { - const route = routeFor(request.model) + const route = routeFor(request.model, request.apiKey) if (route.kind === "stream") return route.stream(request, execute) if (route.kind === "queued") return Stream.unwrap( @@ -77,10 +86,10 @@ export const operations = ( return Stream.fromIterableEffect(Effect.map(route.generate(request, execute), input.responseEvents)) }, start: (request) => start(request).pipe(Effect.map((started) => ({ id: started.id }))), - status: (model, id) => attach(model, id, "status").pipe(Effect.flatMap((route) => route.status)), - result: (model, id) => attach(model, id, "result").pipe(Effect.flatMap((route) => route.result)), - cancel: (model, id) => - attach(model, id, "cancel").pipe( + status: (model, id, options) => attach(model, id, "status", options).pipe(Effect.flatMap((route) => route.status)), + result: (model, id, options) => attach(model, id, "result", options).pipe(Effect.flatMap((route) => route.result)), + cancel: (model, id, options) => + attach(model, id, "cancel", options).pipe( Effect.flatMap( (route) => route.cancel ?? diff --git a/packages/ai/src/media-model.ts b/packages/ai/src/media-model.ts index d5bd0ff80d48..e22010b7ff52 100644 --- a/packages/ai/src/media-model.ts +++ b/packages/ai/src/media-model.ts @@ -3,11 +3,12 @@ import { Effect, Schema } from "effect" import type { HttpClientResponse } from "effect/http" import { Api } from "./api.js" import type { Model } from "./model.js" -import { Auth } from "./route/auth.js" +import { resolve } from "./route/credential.js" import { Endpoint } from "./route/endpoint.js" import { MediaProtocol } from "./route/media-protocol.js" import { MediaRoute } from "./route/media.js" import { AIError, InvalidRequestError, type RequestHttpOptions } from "./schema/index.js" +import { Secret } from "./secret.js" /** * The route a media model runs on: its API's protocol at the API's path and host, with its auth. The API's name and the @@ -16,11 +17,12 @@ import { AIError, InvalidRequestError, type RequestHttpOptions } from "./schema/ export const routeOf = ( model: Model, collect: (events: ReadonlyArray) => Effect.Effect, + apiKey?: MediaRoute.MediaRequest["apiKey"], ): MediaRoute.AnyRoute => { const api = internal(model.api) const composition = { endpoint: Endpoint.path(api.path, { baseURL: Api.baseURL(api.baseURL, model.id) }), - auth: Auth.fromAuthentication(api.auth), + auth: resolve(api.auth, model.auth, apiKey), headers: api.headers, query: api.query, } @@ -38,7 +40,7 @@ export const routeOf = ( - model: MediaRoute.MediaRequest["model"], + request: Pick & { readonly model: Model<"decision" | "embedding"> }, api: Api.Connection & { readonly name: string readonly path: Endpoint.EndpointPart @@ -54,8 +56,9 @@ export const jsonRouteOf = ( } } }, -) => - MediaRoute.inline({ +) => { + const model = request.model + return MediaRoute.inline({ protocol: MediaProtocol.inline( MediaProtocol.identity({ id: api.name, name: api.protocol.name, provider: model.provider }), { @@ -72,9 +75,10 @@ export const jsonRouteOf = ( }, ), endpoint: Endpoint.path(api.path, { baseURL: Api.baseURL(api.baseURL, model.id), query: api.query }), - auth: Auth.fromAuthentication(api.auth), + auth: resolve(api.auth, model.auth, request.apiKey), headers: api.headers, }) +} /** Lift a synchronous Schema-class constructor into a typed `InvalidRequest` failure. */ export const tryRequest = (make: () => A): Effect.Effect => @@ -94,10 +98,17 @@ export const tryRequest = (make: () => A): Effect.Effect => // `http` can carry `fetch`, so it passes through unchecked. const RequestHttp = Schema.declare((_: unknown): _ is RequestHttpOptions => true) +// A secret is kept as the instance it is, so its value stays hidden. +const RequestApiKey = Schema.declare( + (value: unknown): value is string | Secret => typeof value === "string" || value instanceof Secret, +) + /** Parse a normalized request on its schema's type side; models and assets are checked as instances and kept as is. */ export const requestParser = (schema: Schema.Struct) => { const parse = Schema.decodeUnknownSync( - Schema.toType(Schema.Struct({ ...schema.fields, http: Schema.optional(RequestHttp) })), + Schema.toType( + Schema.Struct({ ...schema.fields, http: Schema.optional(RequestHttp), apiKey: Schema.optional(RequestApiKey) }), + ), ) return (normalize: () => unknown) => tryRequest(() => parse(normalize())) } diff --git a/packages/ai/src/model.ts b/packages/ai/src/model.ts index 4ae756e9839f..e87728903bef 100644 --- a/packages/ai/src/model.ts +++ b/packages/ai/src/model.ts @@ -1,4 +1,5 @@ import type { Api } from "./api.js" +import type { AuthSource } from "./auth-source.js" import type { DecisionModelCompatibility } from "./decision.js" import type { Capabilities, @@ -26,6 +27,8 @@ export type Model< readonly kind: K readonly id: ModelID readonly provider: ProviderID + /** The provider's credential, shared by every model it builds. A request's own `apiKey` wins. */ + readonly auth: AuthSource /** Type only: the provider options requests on this model take. */ readonly "~options"?: Options } & Fields[K] diff --git a/packages/ai/src/protocols/utils/responses-compaction.ts b/packages/ai/src/protocols/utils/responses-compaction.ts index 3a1e086bc336..2f472b51908d 100644 --- a/packages/ai/src/protocols/utils/responses-compaction.ts +++ b/packages/ai/src/protocols/utils/responses-compaction.ts @@ -1,4 +1,5 @@ import { internal } from "../../api-internal.js" +import { resolve } from "../../route/credential.js" import { Effect, Schema } from "effect" import { AIError, @@ -12,7 +13,6 @@ import { mergeJsonRecords, } from "../../schema/index.js" import { endpoint, type CompactOperation } from "../../route/client.js" -import { Auth } from "../../route/auth.js" import { stripEffortUpdates } from "../../effort-updates.js" import { foldToolUpdates } from "../../tool-updates.js" import { Endpoint } from "../../route/endpoint.js" @@ -125,7 +125,7 @@ export const make = ( }, body, endpoint: Endpoint.path(url.toString()), - auth: Auth.fromAuthentication(api.auth), + auth: resolve(api.auth, request.model.auth, request.apiKey), encodeBody: Schema.encodeSync(Schema.fromJsonString(Body)), }) const post = yield* ProviderShared.jsonPostEffect({ diff --git a/packages/ai/src/provider.ts b/packages/ai/src/provider.ts index c6ccc4586a42..6a9e545dc9f0 100644 --- a/packages/ai/src/provider.ts +++ b/packages/ai/src/provider.ts @@ -1,10 +1,12 @@ -import { Effect, type Config, type Redacted } from "effect" +import { Config, Effect, Redacted } from "effect" import { Api } from "./api.js" import { internal, view } from "./api-internal.js" import { DecisionModelCompatibility } from "./decision.js" +import { custom, sourceOf, type AuthSource } from "./auth-source.js" import type { Model } from "./model.js" import type { ProviderPackage } from "./provider-package.js" import { Auth } from "./route/auth.js" +import { Secret } from "./secret.js" import { AIError, type Capabilities, @@ -236,10 +238,12 @@ type Without = { [P in keyof T as P extends K ? never : P]: T[P] } export const make = (input: Input) => (settings?: Settings>>): Provider> => { + const auth = credential(input, settings ?? {}) const model = (kind: Api.Kind) => (modelID: string, definition?: Definition) => { const resolved = kind === "language" && definition === undefined ? bundled(input.catalog ?? {}, modelID) : definition - return bind(input, settings ?? {}, kind, select(input, kind, resolved?.api), modelID, resolved) + const api = select(input, kind, resolved?.api) + return bind(input, settings ?? {}, kind, api, auth(api.auth ?? input.auth), modelID, resolved) } const provider: Provider = { ...Object.fromEntries( @@ -253,6 +257,36 @@ export const make = return provider as Provider> } +/** + * The credential each API's models get from one provider call: the `authToken` or `apiKey` setting, one value shared by + * every model, else the API's environment variables. An API whose auth is a definition (signing, OAuth) keeps it. + */ +const credential = (input: Input, settings: Settings & ProviderPackage.Settings) => { + const token = input.auth?.authToken === true ? settings.authToken : undefined + const bearer = token === undefined ? undefined : custom(Auth.bearer(token as string)) + const key = keySource(settings.apiKey) + const env = new Map, AuthSource>() + return (auth: Auth.Authentication | undefined): AuthSource => { + if (bearer !== undefined) return bearer + if (auth === undefined || !Auth.isApiKey(auth)) return sourceOf(auth) + if (settings.apiKey === false) return NONE + if (key !== undefined) return key + // A key from Effect `Config` is read when a request is sent, like the environment. + if (Config.isConfig(settings.apiKey)) return custom(Auth.fromAuthentication(auth, settings.apiKey)) + const vars = env.get(auth.env) ?? sourceOf(auth) + env.set(auth.env, vars) + return vars + } +} + +const NONE: AuthSource = { type: "none" } + +// An empty key reads the environment instead, as no key does. +const keySource = (apiKey: Settings["apiKey"]): AuthSource | undefined => { + const value = typeof apiKey === "string" ? apiKey : Redacted.isRedacted(apiKey) ? Redacted.value(apiKey) : "" + return value === "" ? undefined : { type: "key", key: Secret.make(value) } +} + // Generated data, so it is trusted as a definition without decoding. const bundled = (catalog: Catalog, modelID: string): Definition | undefined => { const api = Object.keys(catalog).find((name) => Object.hasOwn(catalog[name], modelID)) @@ -317,6 +351,7 @@ const bind = ( settings: Settings & ProviderPackage.Settings, kind: K, api: Api.KindMap[K]["api"], + auth: AuthSource, modelID: string, definition: Definition | undefined, ): Model => { @@ -334,7 +369,8 @@ const bind = ( : input.requireBaseURL ? baseURL || invalid(input, "providers require a baseURL") : (baseURL ?? Api.baseURL(api.baseURL, modelID) ?? input.baseURL), - auth: token === undefined ? Auth.fromAuthentication(api.auth ?? input.auth, apiKey) : Auth.bearer(token as string), + // How the API sends a key; the key itself is the model's `auth`. + auth: api.auth ?? input.auth, metadataKey: api.metadataKey ?? input.metadataKey ?? input.id, } // Empty overlays send nothing, so they are left off the model like absent ones. @@ -343,6 +379,7 @@ const bind = ( const deployment = { id: ModelID.make(modelID), provider: ProviderID.make(input.id), + auth, transport: http === undefined ? undefined : { http }, native: options, } @@ -352,6 +389,7 @@ const bind = ( id: modelID, provider: input.id, api: api.with(connection), + auth, options: mergeRequestOptions({ http, native: options }), // A definition's facts go over what the API sets for every model on this host. capabilities: definition?.capabilities diff --git a/packages/ai/src/public.ts b/packages/ai/src/public.ts index 94cea7cdbd0d..3c9e17996643 100644 --- a/packages/ai/src/public.ts +++ b/packages/ai/src/public.ts @@ -197,7 +197,9 @@ export type { export { Media } from "./media.js" export type { Model } from "./model.js" export type { CompactionCapability } from "./api.js" -export type { Reason as GenerationReason, Status as GenerationStatus } from "./generation.js" +export type { AuthSource } from "./auth-source.js" +export { Secret } from "./secret.js" +export type { JobOptions, Reason as GenerationReason, Status as GenerationStatus } from "./generation.js" export type { ExecutableTool, Tool, diff --git a/packages/ai/src/route/client.ts b/packages/ai/src/route/client.ts index 2d145169d8c5..d29c62b9ab67 100644 --- a/packages/ai/src/route/client.ts +++ b/packages/ai/src/route/client.ts @@ -1,7 +1,7 @@ import { internal } from "../api-internal.js" import { Cause, Effect, Option, Schema, Stream } from "effect" import { Api } from "../api.js" -import { Auth } from "./auth.js" +import { resolve } from "./credential.js" import { Endpoint } from "./endpoint.js" import { RequestExecutor } from "./executor.js" import type { HttpMiddleware, TransportRuntime, WebSocketChannelExecutor } from "./transport/index.js" @@ -241,7 +241,7 @@ export const prepareTransport = ( body, request, endpoint: endpoint(api), - auth: Auth.fromAuthentication(api.auth), + auth: resolve(api.auth, request.model.auth, request.apiKey), encodeBody: ProviderShared.encodeJson, middleware: RequestExecutor.withFetch(request.http?.fetch, options?.http), webSocket: options?.webSocket, diff --git a/packages/ai/src/route/credential.ts b/packages/ai/src/route/credential.ts new file mode 100644 index 000000000000..7e16057369df --- /dev/null +++ b/packages/ai/src/route/credential.ts @@ -0,0 +1,28 @@ +import { Effect } from "effect" +import { handlerOf, type AuthSource } from "../auth-source.js" +import { AIError, AuthenticationError } from "../schema/index.js" +import { Secret } from "../secret.js" +import { Auth } from "./auth.js" + +/** + * The auth a request sends: the call's own key, else the model's source, sent as the API's key header says + * (`Authorization: Bearer` when the API names none). + */ +export const resolve = (api: Auth.Authentication | undefined, source: AuthSource, key?: string | Secret) => { + const format = api !== undefined && Auth.isApiKey(api) ? api : Auth.apiKey([]) + if (key !== undefined) return keyed(format, typeof key === "string" ? Secret.make(key) : key) + if (source.type === "custom") + return handlerOf(source) ?? failing("A custom auth source needs the handler its provider made") + if (source.type === "none") return Auth.none + if (source.type === "key") return keyed(format, source.key) + return Auth.fromAuthentication({ ...format, env: source.vars }) +} + +const keyed = (format: Auth.ApiKey, key: Secret) => + // A key that went through JSON comes back as the "" string, not a `Secret`. + !(key instanceof Secret) || Secret.isPlaceholder(key) + ? failing('The API key is the "" placeholder a printed key leaves') + : Auth.fromAuthentication({ ...format, env: [] }, Secret.value(key)) + +const failing = (message: string) => + Auth.custom(() => Effect.fail(new AIError({ reason: new AuthenticationError({ message }) }))) diff --git a/packages/ai/src/schema/options.ts b/packages/ai/src/schema/options.ts index 1f422d42cae4..def5685ce464 100644 --- a/packages/ai/src/schema/options.ts +++ b/packages/ai/src/schema/options.ts @@ -2,6 +2,8 @@ import { Schema } from "effect" import { ModelID, ProviderID } from "./ids.js" import type { Api } from "../api.js" import { internal, view } from "../api-internal.js" +import { sourceOf, type AuthSource } from "../auth-source.js" +import type { Secret } from "../secret.js" import { isModel, type Model } from "../model.js" import { isRecord } from "../utils/record.js" @@ -117,6 +119,8 @@ export interface BaseRequest { readonly model: Model readonly native?: Options readonly http?: RequestHttpOptions + /** This call's API key, sent the way the model's API sends one; it wins over the provider's credential. */ + readonly apiKey?: string | Secret } export const timeoutConfig = (timeout: RequestTimeout | undefined): TimeoutConfig => @@ -446,6 +450,7 @@ const make = < id: ModelID.make(input.id), provider: ProviderID.make(input.provider), api: view(api, input.id), + auth: input.auth ?? sourceOf(api.auth), // The API's options are a preset under the model's own. options: mergeRequestOptions( typeof api.options === "function" ? api.options(input.id) : api.options, @@ -465,6 +470,7 @@ const input = ( ): LanguageModel function update(model: LanguageModel, patch: Partial) { if (Object.keys(patch).length === 0) return model - return make({ ...input(model), ...patch, api: patch.api ?? model.api }) + // A new API that brings its own auth replaces the model's credential, as building the model on it would. + const api = patch.api ?? model.api + const changed = internal(api).auth !== internal(model.api).auth + return make({ + ...input(model), + ...patch, + api, + auth: patch.auth ?? (changed ? sourceOf(internal(api).auth) : model.auth), + }) } /** Builds and changes language model records; a spread works as well. */ @@ -500,6 +514,8 @@ export declare namespace LanguageModel { readonly id: ModelID readonly provider: ProviderID readonly api: Api.LanguageApi + /** The provider's credential; the one the API's own auth implies when omitted. */ + readonly auth?: AuthSource readonly options?: RequestOptions readonly capabilities?: Capabilities readonly compatibility?: LanguageModelCompatibility diff --git a/packages/ai/src/secret.ts b/packages/ai/src/secret.ts new file mode 100644 index 000000000000..56fc7daf5c9d --- /dev/null +++ b/packages/ai/src/secret.ts @@ -0,0 +1,38 @@ +const REDACTED = "" + +/** + * A credential that never prints itself: `String`, `JSON.stringify` and `console.log` all give `""`. + * `Secret.value` is the only way to read it. + */ +export class Secret { + readonly #value: string + + private constructor(value: string) { + this.#value = value + } + + static make(value: string) { + return new Secret(value) + } + + static value(secret: Secret) { + return secret.#value + } + + /** Whether the secret is the `""` placeholder a printed one leaves, not a credential. */ + static isPlaceholder(secret: Secret) { + return secret.#value === REDACTED + } + + toString() { + return REDACTED + } + + toJSON() { + return REDACTED + } + + [Symbol.for("nodejs.util.inspect.custom")]() { + return REDACTED + } +} diff --git a/packages/ai/src/text.ts b/packages/ai/src/text.ts index e25badf0819a..e41949f66220 100644 --- a/packages/ai/src/text.ts +++ b/packages/ai/src/text.ts @@ -483,6 +483,7 @@ export const request = < ...mergeGeneration(input), native: input.native, http: input.http, + apiKey: input.apiKey, cache: input.cache, affinity: input.affinity, includeRaw: input.includeRaw, diff --git a/packages/ai/src/transcription.ts b/packages/ai/src/transcription.ts index 598d2703ce81..d3ad1a65a38b 100644 --- a/packages/ai/src/transcription.ts +++ b/packages/ai/src/transcription.ts @@ -1,5 +1,5 @@ import { Effect, Schema, Stream } from "effect" -import { ProgressEvent, type AwaitOptions, type Job, type Status } from "./generation.js" +import { ProgressEvent, type AwaitOptions, type Job, type JobOptions, type Status } from "./generation.js" import { Media } from "./media.js" import { requestParser } from "./media-model.js" import { isModel, type Model } from "./model.js" @@ -13,11 +13,17 @@ import { AI } from "./ai.js" export type TranscriptionOptions = NativeOptions /** A model on a transcription API: the plain `Model` record of kind `transcription`. */ -export type TranscriptionModel = Model<"transcription", Options> - -export const TranscriptionModelSchema = Schema.declare((value): value is TranscriptionModel => isModel(value, "transcription"), { - expected: "Transcription.Model", -}) +export type TranscriptionModel = Model< + "transcription", + Options +> + +export const TranscriptionModelSchema = Schema.declare( + (value): value is TranscriptionModel => isModel(value, "transcription"), + { + expected: "Transcription.Model", + }, +) // --------------------------------------------------------------------------- // Request @@ -124,7 +130,9 @@ export const TranscriptionEvent = Schema.Union([ export type TranscriptionEvent = Schema.Schema.Type /** Folds a finished transcription stream into its response. */ -export const collectTranscriptionResponse = (events: ReadonlyArray): Effect.Effect => { +export const collectTranscriptionResponse = ( + events: ReadonlyArray, +): Effect.Effect => { const finish = events.find((event) => event.type === "finish") // Every transcription protocol's `finish` emits the terminal event or fails, so a completed stream always has one. if (finish === undefined) return Effect.die(new Error("The transcription stream completed without a finish event")) @@ -182,18 +190,24 @@ export function start(input: TranscriptionRequestInput) { export const status = ( model: TranscriptionModel, id: string, -): Effect.Effect => AI.Service.use((ai) => ai.transcription.status(model, id)) + options?: JobOptions, +): Effect.Effect => + AI.Service.use((ai) => ai.transcription.status(model, id, options)) -/** The finished transcript; fails while the job is still running, or with the provider's reason when it failed. */ +/** The finished result; fails while the job is still running, or with the provider's reason when it failed. */ export const result = ( model: TranscriptionModel, id: string, + options?: JobOptions, ): Effect.Effect => - AI.Service.use((ai) => ai.transcription.result(model, id)) + AI.Service.use((ai) => ai.transcription.result(model, id, options)) /** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */ -export const cancel = (model: TranscriptionModel, id: string): Effect.Effect => - AI.Service.use((ai) => ai.transcription.cancel(model, id)) +export const cancel = ( + model: TranscriptionModel, + id: string, + options?: JobOptions, +): Effect.Effect => AI.Service.use((ai) => ai.transcription.cancel(model, id, options)) export const Transcription = { request, diff --git a/packages/ai/src/utils/sanitize.ts b/packages/ai/src/utils/sanitize.ts index 2fec1ec417c7..a31722f146ad 100644 --- a/packages/ai/src/utils/sanitize.ts +++ b/packages/ai/src/utils/sanitize.ts @@ -1,5 +1,6 @@ import { Schema } from "effect" import { Media } from "../media.js" +import { Secret } from "../secret.js" import { isRecord } from "./record.js" /** @@ -16,8 +17,10 @@ export const sanitizeSurrogates = (value: T): T => { : items ) as T } - // Media assets carry binary or base64 payloads and a lazy byte cache; flattening them into a record would drop both. - if (value instanceof Uint8Array || value instanceof Error || value instanceof Media.Asset) return value + // Media assets carry binary or base64 payloads and a lazy byte cache, and a secret hides its value; flattening either + // into a record would drop them. + if (value instanceof Uint8Array || value instanceof Error || value instanceof Media.Asset || value instanceof Secret) + return value if (!isRecord(value)) return value const entries = Object.entries(value) const sanitized = entries.map(([key, entry]) => [sanitizeSurrogates(key), sanitizeSurrogates(entry)] as const) diff --git a/packages/ai/src/video.ts b/packages/ai/src/video.ts index 3d206b926f45..f4492a15f0da 100644 --- a/packages/ai/src/video.ts +++ b/packages/ai/src/video.ts @@ -1,5 +1,5 @@ import { Effect, Schema, Stream } from "effect" -import { ProgressEvent, type AwaitOptions, type Job, type Status } from "./generation.js" +import { ProgressEvent, type AwaitOptions, type Job, type JobOptions, type Status } from "./generation.js" import { Media } from "./media.js" import { requestParser } from "./media-model.js" import { isModel, type Model } from "./model.js" @@ -150,16 +150,22 @@ export function start(input: VideoRequestInput) { } /** One status read for a job ID. */ -export const status = (model: VideoModel, id: string): Effect.Effect => - AI.Service.use((ai) => ai.video.status(model, id)) - -/** The finished videos; fails while the job is still running, or with the provider's reason when it failed. */ -export const result = (model: VideoModel, id: string): Effect.Effect => - AI.Service.use((ai) => ai.video.result(model, id)) +export const status = ( + model: VideoModel, + id: string, + options?: JobOptions, +): Effect.Effect => AI.Service.use((ai) => ai.video.status(model, id, options)) + +/** The finished result; fails while the job is still running, or with the provider's reason when it failed. */ +export const result = ( + model: VideoModel, + id: string, + options?: JobOptions, +): Effect.Effect => AI.Service.use((ai) => ai.video.result(model, id, options)) /** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */ -export const cancel = (model: VideoModel, id: string): Effect.Effect => - AI.Service.use((ai) => ai.video.cancel(model, id)) +export const cancel = (model: VideoModel, id: string, options?: JobOptions): Effect.Effect => + AI.Service.use((ai) => ai.video.cancel(model, id, options)) export const Video = { request, diff --git a/packages/ai/test/api.types.ts b/packages/ai/test/api.types.ts index 60f55a8996e1..e21b14a49ce5 100644 --- a/packages/ai/test/api.types.ts +++ b/packages/ai/test/api.types.ts @@ -42,6 +42,7 @@ const image: ImageModel = { id: ModelID.make("gpt-image-1"), provider: ProviderID.make("p"), api: OpenAIImagesApi, + auth: { type: "none" }, } // @ts-expect-error a model's kind is its API's const misfiled: ImageModel = { ...image, kind: "video" } diff --git a/packages/ai/test/auth.test.ts b/packages/ai/test/auth.test.ts index 6feb8467f74f..c1a219a24241 100644 --- a/packages/ai/test/auth.test.ts +++ b/packages/ai/test/auth.test.ts @@ -5,6 +5,7 @@ import { ai } from "../src/effect.js" import { Auth } from "../src/route/auth.js" import * as OpenAIChat from "../src/protocols/openai-chat.js" import { LanguageModel } from "../src/schema/index.js" +import { Secret } from "../src/secret.js" import { it } from "./lib/effect.js" const request = ai.request({ @@ -23,6 +24,18 @@ const input = { const withEnv = (env: Record) => Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env }))) describe("Auth", () => { + it.effect("a secret prints as and only Secret.value reads it", () => + Effect.sync(() => { + const secret = Secret.make("sk-fixture") + expect([String(secret), JSON.stringify({ secret }), Bun.inspect(secret)]).toEqual([ + "", + '{"secret":""}', + "", + ]) + expect(Secret.value(secret)).toBe("sk-fixture") + }), + ) + it.effect("renders a config credential as bearer auth", () => Effect.gen(function* () { const headers = yield* Auth.config("OPENAI_API_KEY") diff --git a/packages/ai/test/image-job.test.ts b/packages/ai/test/image-job.test.ts index dcb36105e9e4..c98ab9b84c91 100644 --- a/packages/ai/test/image-job.test.ts +++ b/packages/ai/test/image-job.test.ts @@ -5,6 +5,7 @@ import { Api } from "../src/api.js" import { AI, ai, ImageResponse, Media, ModelID, ProviderID, type ImageModel, type ImageRequest } from "../src/effect.js" import { Google } from "../src/providers/google.js" import { Auth } from "../src/route/auth.js" +import { custom } from "../src/auth-source.js" import { MediaProtocol } from "../src/route/media-protocol.js" import { it } from "./lib/effect.js" import { dynamicResponse, json, observe, settle, type Call } from "./lib/http.js" @@ -69,9 +70,9 @@ const queued = (cancel = true): ImageModel => ({ kind: "image", id: ModelID.make("queued-image"), provider: ProviderID.make("test"), + auth: custom(Auth.bearer("test")), api: Api.http({ name: "test-queued-image", kind: "image", protocol: protocol(cancel), path: "/jobs" }).with({ baseURL: "https://queued.test", - auth: Auth.bearer("test"), }), }) @@ -95,7 +96,10 @@ describe("ai.image.start / status / result / cancel", () => { it.effect("status reads one status per call by job ID", () => Effect.gen(function* () { const calls: Array = [] - const statuses = yield* Effect.all([ai.image.status(model, "job/1"), ai.image.status(model, "job/1")]).pipe( + const statuses = yield* Effect.all([ + ai.image.status(model, "job/1"), + ai.image.status(model, "job/1", { apiKey: "call-key" }), + ]).pipe( Effect.provide( layer((input) => observe(calls, input).pipe( @@ -111,6 +115,8 @@ describe("ai.image.start / status / result / cancel", () => { "GET https://queued.test/jobs/job%2F1", "GET https://queued.test/jobs/job%2F1", ]) + // A call's own key wins over the provider's credential. + expect(calls.map((call) => call.headers.get("authorization"))).toEqual(["Bearer test", "Bearer call-key"]) }), ) diff --git a/packages/ai/test/lib/model.ts b/packages/ai/test/lib/model.ts index 7d9ca3fbdd01..49cceff321fe 100644 --- a/packages/ai/test/lib/model.ts +++ b/packages/ai/test/lib/model.ts @@ -1,9 +1,18 @@ import type { Api } from "../../src/api.js" import { ModelID, ProviderID, type Model, type TransportOptions } from "../../src/effect.js" +import { sourceOf } from "../../src/auth-source.js" /** A model on `api` for `provider`, as a provider's accessor builds one. */ export const bind = >( api: Api.KindMap[K]["api"], provider: string, input: { readonly id: string; readonly transport?: TransportOptions }, -) => ({ ...input, kind: api.kind, id: ModelID.make(input.id), provider: ProviderID.make(provider), api }) as Model +) => + ({ + ...input, + kind: api.kind, + id: ModelID.make(input.id), + provider: ProviderID.make(provider), + api, + auth: sourceOf(api.auth), + }) as Model diff --git a/packages/ai/test/provider/alibaba.test.ts b/packages/ai/test/provider/alibaba.test.ts index 6005c38511fa..52c2c56180c1 100644 --- a/packages/ai/test/provider/alibaba.test.ts +++ b/packages/ai/test/provider/alibaba.test.ts @@ -1,3 +1,4 @@ +import { resolve } from "../../src/route/credential.js" import { internal } from "../../src/api-internal.js" import { expect, test } from "bun:test" import { ConfigProvider, Effect } from "effect" @@ -125,8 +126,8 @@ it.effect("Alibaba resolves explicit auth, API keys, and regional environment cr const base = provider.model("qwen3.8-max", { api }) const model = "auth" in item ? LanguageModel.update(base, { api: base.api.with({ auth: item.auth }) }) : base const request = ai.request({ model, prompt: "Hello" }) - const headers = yield* internal(request.model.api) - .auth.apply({ request, method: "POST", url: "https://fixture", body: "{}", headers: Headers.empty }) + const headers = yield* resolve(internal(request.model.api).auth, request.model.auth) + .apply({ request, method: "POST", url: "https://fixture", body: "{}", headers: Headers.empty }) .pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: item.env })))) expect(headers).toEqual(expect.objectContaining(item.headers)) } diff --git a/packages/ai/test/provider/meta.test.ts b/packages/ai/test/provider/meta.test.ts index 4cb89d1e9944..cac37c909f7c 100644 --- a/packages/ai/test/provider/meta.test.ts +++ b/packages/ai/test/provider/meta.test.ts @@ -1,3 +1,4 @@ +import { resolve } from "../../src/route/credential.js" import { internal } from "../../src/api-internal.js" import { expect } from "bun:test" import { ConfigProvider, Effect } from "effect" @@ -137,7 +138,7 @@ it.effect("Meta resolves environment credentials and accepts explicit auth overr }, ]) { const model = scenario.model() - const headers = yield* internal(model.api).auth.apply({ + const headers = yield* resolve(internal(model.api).auth, model.auth).apply({ request: ai.request({ model, prompt: "Hello" }), method: "POST", url: "https://api.meta.ai/v1/responses", diff --git a/packages/ai/test/provider/minimax.test.ts b/packages/ai/test/provider/minimax.test.ts index 512325b88aac..e8a846dc6255 100644 --- a/packages/ai/test/provider/minimax.test.ts +++ b/packages/ai/test/provider/minimax.test.ts @@ -1,3 +1,4 @@ +import { resolve } from "../../src/route/credential.js" import { internal } from "../../src/api-internal.js" import { describe, expect, test } from "bun:test" import { ConfigProvider, Effect } from "effect" @@ -34,7 +35,7 @@ describe("MiniMax provider", () => { expect(item.model.api.metadataKey).toBe("minimax") expect(item.model.api.baseURL).toBe(`https://api.minimax.io${item.base}`) const url = `${item.model.api.baseURL}${item.path}` - const headers = yield* internal(item.model.api).auth.apply({ + const headers = yield* resolve(internal(item.model.api).auth, item.model.auth).apply({ request, method: "POST", url, @@ -57,7 +58,7 @@ describe("MiniMax provider", () => { yield* compileRequest(request) expect(model.api.baseURL).toBe("https://gateway.example/anthropic/v1") expect(internal(model.api).headers?.({ request })).toEqual({ "anthropic-version": "2023-06-01" }) - const headers = yield* internal(model.api).auth.apply({ + const headers = yield* resolve(internal(model.api).auth, model.auth).apply({ request, method: "POST", url: "https://gateway.example/anthropic/v1/messages", diff --git a/packages/ai/test/provider/moonshot.test.ts b/packages/ai/test/provider/moonshot.test.ts index 4d987b78480a..6d083b98485f 100644 --- a/packages/ai/test/provider/moonshot.test.ts +++ b/packages/ai/test/provider/moonshot.test.ts @@ -1,3 +1,4 @@ +import { resolve } from "../../src/route/credential.js" import { internal } from "../../src/api-internal.js" import { expect } from "bun:test" import { ConfigProvider, Effect } from "effect" @@ -34,7 +35,7 @@ it.effect("Moonshot composes shared protocols with explicit endpoints and bearer expect(url).toBe(`https://api.moonshot.ai${item.path}`) expect(item.model.provider).toBe("moonshotai") expect(item.model.api.metadataKey).toBe("moonshot") - const headers = yield* internal(item.model.api).auth.apply({ + const headers = yield* resolve(internal(item.model.api).auth, item.model.auth).apply({ request, method: "POST", url, @@ -66,7 +67,7 @@ it.effect("Moonshot preserves default reasoning across model IDs on custom endpo expect(compiled.body.thinking).toBeUndefined() expect(compiled.body.reasoning_effort).toBeUndefined() expect(model.api.baseURL).toBe("https://gateway.example/v1") - const headers = yield* internal(model.api).auth.apply({ + const headers = yield* resolve(internal(model.api).auth, model.auth).apply({ request, method: "POST", url: "https://gateway.example/v1/chat/completions", diff --git a/packages/ai/test/provider/venice.test.ts b/packages/ai/test/provider/venice.test.ts index 1808173f3142..4ada6b8de3cb 100644 --- a/packages/ai/test/provider/venice.test.ts +++ b/packages/ai/test/provider/venice.test.ts @@ -1,3 +1,4 @@ +import { resolve } from "../../src/route/credential.js" import { internal } from "../../src/api-internal.js" import { expect } from "bun:test" import { ConfigProvider, Effect } from "effect" @@ -31,7 +32,7 @@ it.effect("Venice owns its endpoint, environment auth, aliases, and SDK-compatib expect(compiled.body.prompt_cache_key).toBe("session-123") expect(compiled.body.store).toBeUndefined() expect(compiled.body.stream_options).toEqual({ include_usage: true }) - const headers = yield* internal(selected.api).auth.apply({ + const headers = yield* resolve(internal(selected.api).auth, selected.auth).apply({ request, method: "POST", url, diff --git a/packages/ai/test/provider/xai-images.test.ts b/packages/ai/test/provider/xai-images.test.ts index d0860133ba3b..1309cfd6a31f 100644 --- a/packages/ai/test/provider/xai-images.test.ts +++ b/packages/ai/test/provider/xai-images.test.ts @@ -5,6 +5,7 @@ import { AI, ai, ModelID, ProviderID } from "../../src/effect.js" import { XAIImages } from "../../src/protocols/xai-images.js" import { XAI } from "../../src/providers/xai.js" import { Auth } from "../../src/route/auth.js" +import { custom } from "../../src/auth-source.js" import { it } from "../lib/effect.js" import { dynamicResponse } from "../lib/http.js" @@ -84,12 +85,12 @@ describe("xAI Images", () => { kind: "image", id: ModelID.make("grok-imagine-image"), provider: ProviderID.make("xai"), - api: XAIImages.api.with({ - baseURL: "https://api.xai.test/v1", - auth: Auth.custom((input) => + api: XAIImages.api.with({ baseURL: "https://api.xai.test/v1" }), + auth: custom( + Auth.custom((input) => Effect.succeed(Headers.set(input.headers, "x-custom-auth", new URL(input.url).hostname)), ), - }), + ), }, prompt: "A robot tending a rooftop garden", }) diff --git a/packages/ai/test/provider/zai.test.ts b/packages/ai/test/provider/zai.test.ts index 1e89f3fcace4..00392c1bda79 100644 --- a/packages/ai/test/provider/zai.test.ts +++ b/packages/ai/test/provider/zai.test.ts @@ -1,3 +1,4 @@ +import { resolve } from "../../src/route/credential.js" import { internal } from "../../src/api-internal.js" import { expect } from "bun:test" import { ConfigProvider, Effect } from "effect" @@ -50,7 +51,7 @@ it.effect("ZAI owns standard and Coding Plan endpoints and bearer credentials", expect(compiled.body.reasoning_effort).toBeUndefined() expect(compiled.body.reasoning).toBeUndefined() expect(compiled.body.output_config).toBeUndefined() - const headers = yield* internal(item.model.api).auth.apply({ + const headers = yield* resolve(internal(item.model.api).auth, item.model.auth).apply({ request, method: "POST", url,