camelAI Documentation

Guides

Models, provider keys, key scopes, and spend limits in camelRun v2

List available models with GET /v2/models, store encrypted provider keys and key scopes, and update agent models or spend limits safely.

View as Markdown

camelRun v2 routes model calls through platform keys (billed against your tenant balance) or your own provider API keys sealed with AES-GCM inside your tenant Durable Object.

List available models (GET /v2/models)

Query GET /v2/models with your tenant API key to inspect the catalog and see which models are currently available to your tenant (or a specific keyScope):

bash
curl -s "https://run.camelai.com/v2/models?available=true" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY"

Query parameters:

  • provider: filter by provider name (for example openai, anthropic, gemini, openrouter, azure).
  • available=true: return only models backed by a configured tenant key, key scope, or platform key.
  • keyScope: check availability against a named key scope instead of tenant defaults (platform keys are excluded when keyScope is set).

Virtual model aliases

AliasResolves to
camelrun/defaultazure/gpt-6.2-sol (or the Worker's configured DEFAULT_MODEL)
camelrun/fastopenrouter/meta/muse-ember
muse-ember / meta/muse-emberopenrouter/meta/muse-ember

Bring your own provider keys (/v2/providers)

Store credentials for openai, openai-responses, anthropic, gemini (or google), openrouter, azure, or a custom provider name (custom/... or any custom slug with apiStyle). Keys are sealed at rest with AES-GCM using VAULT_SECRET and never returned in plaintext.

ts
await client.providers.set("anthropic", {
  apiKey: process.env.ANTHROPIC_API_KEY!,
});

Over REST

bash
# Set or update a provider key
curl -s -X PUT "https://run.camelai.com/v2/providers/openai" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "apiKey": "sk-...",
    "baseUrl": "https://api.openai.com/v1",
    "modelAliases": { "fast": "gpt-4.1-mini" }
  }'

# List configured providers (never returns plaintext secrets)
curl -s "https://run.camelai.com/v2/providers" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY"

# Delete a provider key
curl -s -X DELETE "https://run.camelai.com/v2/providers/openai" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY"

Provider upsert body fields:

FieldTypeDescription
apiKeystringProvider API key (required unless non-empty headers are supplied)
baseUrlstring | nullOptional custom upstream base URL
modelAliasesRecord<string, string>Optional map of alias names to upstream model IDs (aliases appear in GET /v2/models as <provider>/<alias>)
headersRecord<string, string> | nullOptional custom auth/request headers sent upstream
apiStyle"openai-chat" | "openai-responses" | "anthropic" | "gemini" | nullProtocol to speak for custom or gateway endpoints (see Custom models)

Key scopes (/v2/key-scopes)

Key scopes isolate provider credentials per customer, workspace, or environment within a single tenant. A scope name is 1 to 100 characters.

bash
# Store a scoped OpenAI key for customer-42
curl -s -X PUT "https://run.camelai.com/v2/key-scopes/customer-42/providers/openai" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKey": "sk-customer-42-..."}'

# List providers in a key scope
curl -s "https://run.camelai.com/v2/key-scopes/customer-42/providers" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY"

# Remove one provider from a scope, or delete the entire scope
curl -s -X DELETE "https://run.camelai.com/v2/key-scopes/customer-42/providers/openai" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY"
curl -s -X DELETE "https://run.camelai.com/v2/key-scopes/customer-42" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY"

Attach a keyScope when upserting an agent (PUT /v2/agents/:key), patching its model (PATCH /v2/agents/:idOrKey/model), or overriding it on a single run (POST /v2/agents/:idOrKey/runs with { keyScope }) or voice call (POST /v2/voice/calls with { keyScope }). When a keyScope is set, camelRun resolves keys exclusively from that scope and does not fall back to platform keys.

Safe idle updates for model and spend limit

To change an agent's model or spend limit without racing against an active turn or concurrent update, use the compare-and-swap PATCH endpoints (tenant API key required):

Update model while idle (PATCH /v2/agents/:idOrKey/model)

bash
curl -s -X PATCH "https://run.camelai.com/v2/agents/support-42/model" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4-0",
    "expectedModel": "azure/gpt-6.2-sol",
    "keyScope": null
  }'

Returns { "model": "anthropic/claude-sonnet-4-0", "changed": true }. Returns 409 model_changed if the agent's current model does not match expectedModel, or 409 agent_busy if any run is queued, running, or input_required.

Update spend limit while idle (PATCH /v2/agents/:idOrKey/spend-limit)

bash
curl -s -X PATCH "https://run.camelai.com/v2/agents/support-42/spend-limit" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "spendLimitUsd": 20,
    "expectedSpendLimitUsd": 10
  }'

Returns { "spendLimitUsd": 20, "changed": true }. Returns 409 spend_limit_changed on mismatch or 409 agent_busy if the agent has active or pending work.

For per-run spending caps (spendLimitUsd on POST /v2/agents/:idOrKey/runs, which requires whileRunning: "queue"), see Pricing and billing.