Skip to main content
Agent

Models & Credentials

Choose coding-agent models, pass provider credentials securely to agentOS sessions, and control which secrets are available to each adapter.

  • 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.

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:

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:

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 page for supported models and providers.

Embedded API

Pass provider credentials through env on vm.sessions.open(). The host owns the mapping between callers and VM handles.

import pi from "@agentos-software/pi";
import { AgentOs } from "@rivet-dev/agentos-core";

const apiKey = process.env.ANTHROPIC_API_KEY;
if (!apiKey) {
	throw new Error("Set ANTHROPIC_API_KEY before running this example.");
}

const vm = await AgentOs.create({ software: [pi] });

try {
	await vm.sessions.open({
		agent: "pi",
		env: { ANTHROPIC_API_KEY: apiKey },
	});
} finally {
	await vm.dispose();
}

Read more in the embedded API quickstart.