# Models & Credentials

- Choose the model through your **agent adapter**.
- Pass provider credentials from trusted server code.
- Credentials are injected at session creation and can be isolated per tenant.
- The VM does **not** inherit the host `process.env` — keys must be passed
  explicitly.

## Passing API keys

Pass LLM provider keys via the `env` option on `openSession`.

examples/llm-credentials/client.ts:

```ts
import { createClient } from "@rivet-dev/agentos/client";
import type { registry } from "./server";

const client = createClient<typeof registry>({
	endpoint: "http://localhost:6420",
});

// Pass LLM provider keys via the `env` option on openSession. The VM does
// not inherit from the host process.env, so keys must be passed explicitly.
await client.vm.getOrCreate("my-agent").sessions.open({
	agent: "pi",
	env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY! },
});
```

## Per-tenant credentials

- Key `getOrCreate` on the tenant id → isolated VM per tenant.
- Look up the tenant's key on the server, inject via session `env`.
- Keys stay on the server and never reach the client, and one tenant's key
  never reaches another.

Declare the agent software on the server:

examples/llm-credentials/server.ts:

```ts
import { agentOS, setup } from "@rivet-dev/agentos";
import pi from "@agentos-software/pi";

// The VM does not inherit the host process.env. LLM provider keys are passed
// explicitly per session, so the server just declares the agent software here.
const vm = agentOS({
	software: [pi],
});

export const registry = setup({ use: { vm } });

registry.start();
```

Resolve each tenant's key and pass it at session creation:

examples/llm-credentials/per-tenant.ts:

```ts
import { createClient } from "@rivet-dev/agentos/client";
import type { registry } from "./server";

const client = createClient<typeof registry>({
	endpoint: "http://localhost:6420",
});

// Stand-in for your own per-tenant credential store.
declare function lookupTenantApiKey(tenantId: string): Promise<string>;

// Give each tenant an isolated VM keyed by their tenant id, then inject that
// tenant's API key from your database at session creation. Keys stay on the
// server and never reach the client.
async function startTenantSession(tenantId: string) {
	const anthropicApiKey = await lookupTenantApiKey(tenantId);

	await client.vm.getOrCreate(tenantId).sessions.open({
		agent: "pi",
		env: { ANTHROPIC_API_KEY: anthropicApiKey },
	});
}

await startTenantSession("tenant-123");
```

## Models

- Model selection belongs to the configured agent adapter.
- AgentOS forwards the session environment and preserves the agent's native
  model behavior — no second model-selection layer.
- See your [agent](/agentos/docs/agents/pi) page for supported models and providers.
