@pleach/transport-azure-openai
First-party Azure OpenAI Service transport for cloud-routed Pleach runtimes — API-key, token-callback, or opt-in managed-identity auth, deployment-name routing, and generic auth errors.
Not yet published. @pleach/transport-azure-openai is marked
private in this monorepo and is not on npm —
npm install @pleach/transport-azure-openai will not resolve today.
This page documents the planned surface; the package publishes in a
later cut.
@pleach/transport-azure-openai is the Azure OpenAI Service
route for a Pleach session whose buyer reaches OpenAI models
through their Azure tenancy rather than the direct OpenAI API.
createAzureOpenAIProvider(config) returns an AgentProvider that
POSTs to the Azure chat-completions endpoint and decodes the
text/event-stream response. The @azure/openai SDK isn't required.
Cascade decisions and audit shape are the same as any other provider;
only the transport and the credential source change.
What it provides
- An
AgentProvider(execute+abort+capabilities) for the OpenAI family on Azure (gpt-4o,gpt-4o-mini,o1,o3-mini, …). Anthropic-via-Azure and Mistral-via-Azure throw"family not yet supported"at invoke time. - Three auth modes: a static
apiKey, anazureADCredentialstoken callback, or the host's managed identity via an explicitcredential: "default". - Deployment-name routing, since Azure addresses models by deployment
name:
providerConfig.deployment, thendefaultDeployment, then the model id. - Generic auth errors: the stream never carries the underlying credential error or an HTTP 401/403 body.
createResolveRegion(config)andregionFromEndpoint(endpoint), which read the region from a regional*.<region>.api.cognitive.microsoft.comhostname and returnnullfor*.openai.azure.com.- Per-call abort: each
execute()owns its ownAbortController.abort()cancels every in-flight call.
Where it fits
@pleach/transport-azure-openai plugs into the same provider
slot on SessionRuntime that the direct-API providers fill — it
satisfies the AgentProvider contract documented in
Providers. For the architectural shape of a
cloud-routed deployment — transport vs family, IAM federation,
region as a hard constraint, cost reconciliation — see
Cloud-routed agent.
Install
This package is not on npm yet, so there is no npm install step.
Build it from the source repository and add it as a workspace
dependency alongside @pleach/core:
{
"dependencies": {
"@pleach/core": "0.1.0",
"@pleach/transport-azure-openai": "workspace:*"
}
}Once the package publishes, this page will switch to a regular
npm install.
@azure/identity (^4.0.0) is an optional peer dependency,
imported lazily and only on the credential: "default" path. If it's
absent there, the first execute() throws a "missing optional peer
dependency @azure/identity" error. API-key and token-callback auth
need nothing extra.
Auth
Exactly one mode applies. azureADCredentials wins over apiKey when
both are set. Construction throws when no auth is configured, when
apiKey is an empty string, or when credential: "default" is
combined with either of the other two.
Managed identity is opt-in
Managed identity is never a fallback. On a multi-tenant or BYOK host,
a tenant whose key is missing must fail, not silently authenticate as
(and bill to) the host's own identity. To use the host's identity,
install @azure/identity and set credential: "default":
import { createAzureOpenAIProvider } from "@pleach/transport-azure-openai";
const provider = createAzureOpenAIProvider({
endpoint: "https://my-resource.openai.azure.com",
credential: "default",
defaultDeployment: "prod-gpt4o",
});Because the host's Entra token is attached, the endpoint must be
https on *.openai.azure.com or *.cognitiveservices.azure.com, or an
exact hostname listed in allowedEndpointHosts (a private gateway, for
example). Any other endpoint throws at construction.
The transport builds one DefaultAzureCredential per provider,
requests a token for https://cognitiveservices.azure.com/.default,
and caches it until credentialRefreshSkewMs before expiry. The skew
must be a finite number >= 0 and defaults to 300000 (5 minutes).
Token callback
For a specific credential, such as a user-assigned identity, pass
azureADCredentials: () => Promise<string>. It runs on every request,
so cache inside it if you need to.
Auth errors
A credential failure yields one error event with the fixed text
"azure-openai: authentication failed". The underlying error goes only
to the optional onAuthError(error) hook, and a throwing hook is
ignored. An HTTP 401/403 from Azure is handled the same way: its body
isn't echoed, and the cached managed-identity token is dropped so the
next request mints a new one.
Configuration
| Field | Type | Notes |
|---|---|---|
endpoint | string | Azure OpenAI resource endpoint. |
apiKey | string? | Static key; must be non-empty when present. |
azureADCredentials | () => Promise<string>? | Bearer-token callback, invoked per request. |
credential | "default"? | Opt in to DefaultAzureCredential. Never implied. |
allowedEndpointHosts | string[]? | credential: "default" only: extra exact hostnames the token may be sent to (https only). |
credentialRefreshSkewMs | number? | credential: "default" only. Default 300000. |
onAuthError | (error: unknown) => void? | Receives the underlying credential error. |
defaultDeployment | string? | Default deployment; providerConfig.deployment overrides per call. |
defaultModelId | string? | Default model id; AgentExecutionConfig.model overrides per call. A call with neither throws. |
apiVersion | string? | Azure OpenAI REST API version. Default "2024-10-21". |
The package's README and src/types.ts in the
source repository are the
reference. If a claim here disagrees with the source, the source wins.
Where to go next
Cloud-routed agent
Transport-vs-family, IAM federation, region pinning, and cost reconciliation to the cloud invoice.
Providers
The AgentProvider contract this transport implements and the cascade rules it threads through.
Multi-tenant SaaS agent
Per-tenant runtime construction when each tenant reaches its own Azure tenancy.
Host adapter
`setHarnessModuleLoader` — the dynamic-import seam hosts mid-migration use to wire their own implementations of capabilities the substrate hasn't fully absorbed yet.
@pleach/transport-bedrock
First-party AWS Bedrock transport for cloud-routed Pleach runtimes — static or per-request AWS credentials with refresh before expiry, region pinning, and generic auth errors.