Configuration
Configure providers, base URLs, SDK clients, and provider-specific request fields.
Configuration can happen at three levels: provider discovery, SDK client construction, and an individual request.
Provider configuration
AnyLLM.create() accepts a provider name and ProviderOptions:
import { AnyLLM } from "any-llm-ts";
const llm = AnyLLM.create("openai", {
apiKey: process.env.OPENAI_API_KEY,
apiBase: "https://api.openai.com/v1",
clientOptions: {
maxRetries: 3,
timeout: 30_000,
},
});| Option | Purpose |
|---|---|
apiKey | Overrides the provider's conventional API-key environment variable. |
apiBase | Overrides the configured API base URL or endpoint. |
clientOptions | Passes additional constructor options to the underlying provider SDK. |
The values in clientOptions are intentionally typed as Record<string, unknown> because the
accepted keys differ between SDKs and versions.
Request-specific fields
Use providerOptions for request properties not represented by the common interface:
await llm.completion({
model: "provider-model-name",
messages: [{ role: "user", content: "Hello" }],
providerOptions: {
service_tier: "priority",
},
});providerOptions is merged into the outgoing payload after normalized fields, so it can override
wire-level values. That is useful as an escape hatch, but it also means you should validate or
hard-code these options rather than accepting them directly from untrusted callers.
Azure OpenAI
Azure OpenAI uses the v1 API at {endpoint}/openai/v1/. Dated apiVersion values and
azureDeployment client options are rejected; pass the deployment name as model on each request.
Image, transcription, and speech calls add api-version=preview unless the caller already set a
query version.
export AZURE_OPENAI_ENDPOINT="https://example.openai.azure.com"
export AZURE_OPENAI_API_KEY="..."
# or
export AZURE_OPENAI_AD_TOKEN="..."const azure = AnyLLM.create("azureopenai");You can pass OpenAI SDK constructor fields through clientOptions, including
azureADTokenProvider for Entra ID. apiKey, azureADToken, and azureADTokenProvider are
mutually exclusive.
Inspect effective metadata
const metadata = AnyLLM.getProviderMetadata("openai");
console.log(metadata.envApiKey);
console.log(metadata.apiBase);
console.log(metadata.capabilities.streaming);
console.log(metadata.capabilities.pdfInput);
console.log(metadata.promptCacheKeySupport);
console.log(metadata.tier);Metadata is returned as a clone, so changing the returned object does not modify the registry.
tier mirrors the Python project's credential-backed verification matrix. It describes provider
integration coverage, not whether every model and operation is available in your account.
When promptCacheKeySupport is unsupported, passing promptCacheKey to completions, Responses,
or Messages fails before a network request. supported means the provider handles the key
directly; passthrough means a router or custom compatible endpoint receives it unchanged.