# Cloud-routed agent (/docs/cloud-routed-agent)



A cloud-routed agent is the shape an enterprise reaches for when
direct provider API keys are forbidden by policy and inference
has to land inside the customer's VPC. The model family is the
same as the direct-API shape — `anthropic`, `openai`,
`google` — but the transport is AWS Bedrock, Azure OpenAI
Service, or Google Vertex AI. IAM federates the credential;
region pinning is enforced by the cloud, not the runtime.

<Callout type="warn">
  **Transport packages not yet published.**
  `@pleach/transport-bedrock`, `@pleach/transport-azure-openai`, and
  `@pleach/transport-vertex` are marked `private` in the monorepo and are
  not on npm yet — the `npm install` / import lines below will not
  resolve today. This page documents the planned integration shape; the
  transport packages publish in a later cut.
</Callout>

This page walks the four pieces a security architect asks about:
the transport-vs-family separation, IAM-federated credential
resolution, region constraints, and the cost row that ties the
cloud invoice back to the runtime.

**Related shapes.**
[Region-pinned agent](/docs/region-pinned-agent) if the same
buyer also locks family per call class and runs a parity suite.
[Multi-tenant SaaS agent](/docs/multi-tenant-saas-agent) if one
runtime serves many customers, each reaching their own cloud
account.
[Regulated-domain agent](/docs/regulated-domain-agent) if the
regulator drives the constraint and the cloud is the substrate
that makes the deployment reachable.

## What you're building [#what-youre-building]

A turn loop whose provider boundary is the cloud, not the lab.
The shape is the same regardless of which cloud the buyer
landed on:

* Family is the model's identity (`anthropic`, `openai`,
  `google`); transport is the route to it (`bedrock`,
  `azure-openai`, `vertex`).
* The credential is an IAM role, a managed identity, or a
  workload-identity binding — never a long-lived API key.
* The endpoint is a VPC endpoint, a PrivateLink, or a private
  service connect URL. The cloud enforces that the call doesn't
  leave the perimeter.
* The cost row carries the provider, the transport, the model, and
  the token counts — so the runtime ledger reconciles to the cloud
  invoice.

## Transport vs family [#transport-vs-family]

The same family routes through different transports without
forcing a different cascade decision. A session asking for
`anthropic` can land on the direct API, Bedrock, or both via
failover — the cascade rules don't change.

```typescript
// lib/runtime.ts
import { SessionRuntime, definePleachPlugin } from "@pleach/core";

export function buildCloudRoutedRuntime(req: AuthedRequest) {
  return new SessionRuntime({
    provider:     bedrockProvider,                 // transport
    storage:      new SupabaseAdapter({ client: supabase }),
    checkpointer: new SupabaseSaver({ client: supabase }),
    plugins:      [definePleachPlugin("cleared-tools", { tools: clearedTools })],
    permittedFamilies: new Set(["anthropic"]),     // family lock
    // Transport ("bedrock") and region ("us-east-1") are pinned at the
    // provider — `bedrockProvider` above IS the transport, constructed
    // against the cleared AWS region — not via a session-config field.
    tenantId:          req.tenantId,
  });
}
```

Why the separation matters under a contract clause: a buyer who
clears `anthropic` through Bedrock for `us-east-1` hasn't cleared
the same family through Azure OpenAI for `westeurope`. The
transport pin is the structural piece that keeps the cascade
inside the cleared substrate.

## IAM-federated credentials [#iam-federated-credentials]

The credential resolver is per-request: an AWS credential provider for
Bedrock, managed identity for Azure, Application Default Credentials
(including workload identity) for Vertex. The runtime doesn't hold a
long-lived key; the cloud's identity layer hands out a short-lived
credential that the transport refreshes.

```typescript
// lib/providers/bedrock.ts
import { createBedrockProvider } from "@pleach/transport-bedrock";
import { fromContainerMetadata } from "@aws-sdk/credential-providers";

export const bedrockProvider = createBedrockProvider({
  region:             "us-east-1",
  credentialProvider: fromContainerMetadata(), // resolved per request, refreshed before expiry
  defaultModelId:     "anthropic.claude-3-5-sonnet-20241022-v2:0",
});
```

Pass the provider function itself, not a resolved credential. The
transport calls it on the first request and again before the cached
credentials expire (5 minutes early by default, set with
`credentialRefreshSkewMs`). Azure's managed identity is opt-in
(`credential: "default"`), and Vertex falls back to ambient ADC when
`credentials` is omitted. See each transport page for the per-cloud
rules.

The credential itself never reaches the stream. A credential failure
surfaces as a generic `"<transport>: authentication failed"` error
event, and the underlying error goes only to the server-side
`onAuthError` hook.

## What today ships [#what-today-ships]

Today, `@pleach/core` ships the family-strict cascade,
`permittedFamilies`, the deterministic replay path, and the
audit row that records provider, transport, and model. Bring-your-
own-provider via the `AgentProvider` contract is the supported
extension point: a host running a Bedrock, Azure OpenAI, or
Vertex endpoint implements the contract directly and threads
the cascade.

For the direct-API path (provider keys held by the runtime),
`AnthropicSdkProvider` and `AiSdkProvider` ship in core.

## What you provide [#what-you-provide]

### Setup [#setup]

* **Endpoint configuration.** Point the transport at your PrivateLink
  or private endpoint yourself.
* **A key store for signing,** KMS or Vault.

### Not in Pleach yet [#not-in-pleach-yet]

* **Published cloud transports.** Until the transport packages publish,
  implement `AgentProvider` against the cloud API directly.
* **Security-tool routing.** To route audit rows into AWS Security
  Hub, Azure Sentinel or GCP Chronicle, read them from your ledger and
  forward them.

## Region as a hard constraint [#region-as-a-hard-constraint]

Region is enforced by the cloud at the endpoint URL. A request
to a `us-east-1` Bedrock endpoint can't land on a `us-west-2`
model — the cloud rejects it before the runtime sees the
response. The audit row has no region column. The region lives in
your endpoint configuration and in the cloud's own request log, so
reconcile out-of-region rejections against the cloud side.

A buyer with EU residency policy pins the runtime to a
`eu-central-1` transport and rejects any session whose context
asks for a different region. The check is a one-line precondition
on `buildCloudRoutedRuntime`; the cloud is the enforcement
authority.

## Cost reconciliation to the cloud invoice [#cost-reconciliation-to-the-cloud-invoice]

The audit row carries the provider, the transport, the model, and
the token counts — the same dimensions the cloud's billing detail
breaks out, minus region. Reconciliation is one join, not a
parallel cost pipeline.

Take the call ledger's rows from the start of the month. Group them by
provider, transport and model, and count the calls and sum the input and
output tokens for each group.

The cloud invoice rolls up the same dimensions; take region from
the invoice side. A finance reviewer reading both surfaces sees the
same numbers.

## Where to go next [#where-to-go-next]

<Cards>
  <Card title="Providers" href="/docs/providers" description="The AgentProvider contract — the extension point a cloud transport implements." />

  <Card title="Family lock" href="/docs/family-lock" description="The permittedFamilies constraint that scopes which families a session can ever reach." />

  <Card title="Region-pinned agent" href="/docs/region-pinned-agent" description="The sibling shape for direct-API buyers running per-call-class family pins and parity suites." />

  <Card title="Audit ledger" href="/docs/audit-ledger" description="The call ledger schema and the fields the cost reconciliation reads." />

  <Card title="Multi-tenant SaaS agent" href="/docs/multi-tenant-saas-agent" description="Per-tenant runtime construction when each tenant reaches its own cloud account." />

  <Card title="Air-gapped deployment" href="/docs/air-gapped-deployment" description="The substrate posture for a perimeter-bound deployment, when the cloud is fully on-prem." />
</Cards>
