camelRun by camelAI

Multi-tenant AI agents

One keyed AI agent per user or thread, with scoped browser tokens and verified MCP identity.Give every user or conversation in your SaaS app a keyed AI agent on camelRun. Each agent wakes on request, sleeps at $0, scopes browser access to one agent, and passes verified user identity to runtime-authenticated MCP servers.

thread-4127: new agent

RunningAsleepNo agent yet

Agent keys

One AI agent per user

Upsert an agent with an ID from your app on PUT /v2/agents/:key: a user, a thread, or a customer workspace. The same key always addresses the same isolated Durable Object, history, and camelFS repo. Only your tenant key can set toolIdentity, actor, or keyScope. camelRun runs thousands of agents at once.

handler.ts
const headers = {
  Authorization: `Bearer ${process.env.CAMELRUN_API_KEY}`,
  "Content-Type": "application/json",
};
const agent = await fetch(`https://run.camelai.com/v2/agents/thread-${thread.id}`, {
  method: "PUT", headers,
  body: JSON.stringify({
    definition: "support",
    toolIdentity: { subject: thread.ownerId, context: { org: thread.orgId } },
    keyScope: thread.orgId, // optional customer BYOK key scope
  }),
}).then((r) => r.json()); // { id, key, agentToken: "agt_tok_...", repoId }
const run = await fetch(`https://run.camelai.com/v2/agents/${agent.key}/runs`, {
  method: "POST", headers,
  body: JSON.stringify({ prompt: message, actor: currentUser.id, spendLimitUsd: 0.25 }),
}).then((r) => r.json());

Signed tool identity

Every runtime MCP call says which user it's for

Point your agents at one remote MCP server with auth: { type: "runtime" }. camelRun signs every call with a short-lived Ed25519 JWT carrying tenant, agent, subject (sub), authenticated run actor (act), and context (ctx), with zero static API keys. Webhook tools receive X-CamelRun-Agent, X-CamelRun-Run, and your configured headers, plus a signed callback token on async 202 tools.

Verify the JWT against /v2/.well-known/jwks.json and check tenant and audience. Calls from another camelRun account are rejected before your code touches a database.

app.example.com/mcp
tools/call
  1. get_assignmentuser-123 · org_abc123200
  2. list_todosuser-456 · org_abc123200
  3. get_assignmentuser-311 · org_q81x7d200
  4. get_assignmentuser-123 · another account401
get_assignment reads
jwt.act
"user-123"
jwt.ctx
{ org: "org_abc123" }
auth.ts
import { createRemoteJWKSet, jwtVerify } from "jose";
const JWKS = createRemoteJWKSet(new URL("https://run.camelai.com/v2/.well-known/jwks.json"));

export async function authorizeMcpCall(req: Request) {
  const token = req.headers.get("authorization")?.replace(/^Bearer /, "") ?? "";
  const { payload } = await jwtVerify(token, JWKS, {
    issuer: "https://run.camelai.com/v2",
    audience: "https://app.example.com/mcp",
  });
  if (payload.tenant !== process.env.CAMELRUN_TENANT_ID) throw new Response("Forbidden", { status: 401 });
  return db.todos({ user: String(payload.act ?? payload.sub), org: (payload.ctx as { org: string }).org });
}
definition.ts
await fetch("https://run.camelai.com/v2/definitions/support", {
  method: "PUT", headers,
  body: JSON.stringify({
    mcpServers: [{ name: "app", url: "https://app.example.com/mcp", auth: { type: "runtime" } }],
  }),
});

Agent-scoped tokens

Let each user connect straight to their agent

PUT /v2/agents/:key returns a browser-safe agt_tok_… token scoped to that single agent. After your backend checks access, hand that token to the browser to stream SSE events, read history, start runs, and answer ordinary inputs directly against camelRun. Admin actions like DELETE, config changes, actor overrides, and other agents return 403.

app.example.com/threads/4127

Lab report: plant growth

user-123

Can you check my lab report intro? It's due Friday.

get_assignmentdone

Message your tutor
thread-4127
agt_tok_…
token scope1 agent only
  • GET200SSE stream
    /v2/agents/thread-4127/events
  • POST200single agent
    /v2/agents/thread-4127/runs
  • DELETE403
    /v2/agents/thread-4127
token.ts
// POST /api/threads/:id/token, after checking the user may access this thread
const res = await fetch(`https://run.camelai.com/v2/agents/thread-${threadId}`, {
  method: "PUT", headers,
  body: JSON.stringify({ definition: "support", toolIdentity: { subject: user.id } }),
});
const { agentToken, key } = await res.json(); // agt_tok_... scoped to one agent
return Response.json({ token: agentToken, url: `https://run.camelai.com/v2/agents/${key}` });

Key scopes & spend caps

Let each customer bring their own LLM API key

Store each customer's provider keys in a named scope via PUT /v2/key-scopes/:scope/providers/:provider and pass that keyScope on their agents. Their agents call models with their own keys, camelRun charges $0 for model tokens on BYOK, and rotating a key takes effect on the next call.

Track per-user allowances in your app, pass per-run spendLimitUsd on each request, and reconcile actual usage with models and keys.

RunningAsleepNo agent yetKey in use

FAQ

Questions about multi-tenant AI agents

How do I give every user their own AI agent?

Call PUT /v2/agents/:key with an ID from your app, such as user-123 or thread-4127. The first request creates the agent and later calls address the same isolated Durable Object, with its history and files. Set toolIdentity with your tenant key and pass the authenticated actor on runs.

How do I keep each customer's data separate?

Each keyed agent runs in its own SQLite Durable Object with its own conversation history and versioned camelFS repo, and runtime-authenticated MCP calls carry signed tenant, sub, act, and ctx claims for your backend to enforce. Tenants cannot list, read, run, or delete another tenant's agents. If your data must stay in your own Cloudflare account, you can self-host the open-source runtime.

Can each customer bring their own model API key?

Yes. Save each customer's keys with PUT /v2/key-scopes/:scope/providers/:provider and attach keyScope to their agents. Model tokens on customer keys cost $0 from camelRun. Agents without a scope fall back to your tenant keys or platform keys.

Can the browser talk to an agent without my API key?

Yes. Hand the browser the agt_tok_… token from PUT /v2/agents/:key. It can stream SSE events, read history, start runs, and answer ordinary inputs for that agent. DELETE, config escalations, actor or keyScope overrides, and requests for other agents return 403. Your tenant API key never leaves your server.

How does it scale to thousands of users?

camelRun runs thousands of agents at once on Cloudflare Durable Objects, and sleeping or parked agents cost $0. Active agent time is $0.05 per active agent-hour, active Linux containers for bash bill $0.00005/sec ($0.18/hr) with free pre-warming, and camelFS and history storage is $0 right now.

Can I cap what each user's agent spends?

Yes. Track each user's allowance in your application, pass a per-run spendLimitUsd on POST /v2/agents/:key/runs (with whileRunning set to queue), and reconcile metered usage from the run record or usage webhooks.

Can I delete a user's agent and everything in it?

Yes. DELETE /v2/agents/:key with your tenant API key destroys the agent's durable state and index entry. If the agent also uses a camelFS repository you want removed, delete the repo separately with DELETE /v2/repos/:repoId.

More on per-user AI agents

Start building

Give your first user an AI agent

Get an API key, upsert a keyed agent per user or thread, and connect your runtime-authenticated MCP server. The guides cover identity, agent tokens, and customer key scopes.

Connect your coding agent (no key)

claude mcp add --transport http camelrun https://run.camelai.com/mcp

Adds camelRun's hosted MCP server to Claude Code (also works with Codex and ChatGPT). Signing in creates your account automatically.