ai.wire.resolve_credential

Collapse a client's `ai.Credential?` option to the value to put on the wire, reading the environment at REQUEST time (never at construction).

Reference version

Signature

function ai.wire.resolve_credential(
cred: ai.Credential | null,
env_fallback: string | null
) -> string | null throws baml.errors.Io | baml.errors.ParseError

Collapse a client's ai.Credential? option to the value to put on the wire, reading the environment at REQUEST time (never at construction).

  • a literal string resolves to itself, unless it is blank — a whitespace-only credential is treated as "not configured" so the rest of the chain can supply one;
  • a baml.env.Ref resolves to ref.get()null when the named variable is unset, which lets the caller continue down its own chain (or raise the same error it raises for an unconfigured option);
  • null falls back to env_fallback, the provider's canonical variable name, looked up with baml.env.get. A null env_fallback means the provider has no canonical variable and the result is null.

A BLANK value is "not configured" at EVERY rung, not just the literal one: export OPENAI_API_KEY= otherwise resolved to "" and every client built Authorization: Bearer — a provider 401 in place of the local "no credential configured" error the same client raises when the variable is absent entirely. The two spellings of "I did not set this" now behave alike.

This IS the whole chain a client needs: explicit credential (a literal or an env.NAME ref) → the provider's canonical variable (env_fallback).

Source:<builtin>/ai/ns_wire/wire.bamlbytes 15382045