Skip to content

Create Session

POST/v1/sessions

Create a new session. A session is a running instance of an agent within an environment, maintaining state across multiple interactions.

Claude API compatibility

SandBase implements a subset of the Claude Managed Agents Session API. The fields documented below are supported today. Additional Claude fields are noted as roadmap items.

Request Parameters

ParameterTypeRequiredDescription
agentstring | objectAgent identifier. String (uses latest version) or object with id and version.
environment_idstringID of the environment defining the container configuration.
titlestringHuman-readable session title.
metadataobjectArbitrary key-value metadata. Max 16 pairs, keys up to 64 chars, values up to 512 chars.

Agent Parameter

The agent field accepts two formats:

jsonc
// String — uses latest version
"agent_01HqR2k7vXbZ9mNpL3wYcT8f"

// Object — pin to specific version
{
  "type": "agent",
  "id": "agent_01HqR2k7vXbZ9mNpL3wYcT8f",
  "version": 2
}
FieldTypeRequiredDescription
typestringAlways "agent"
idstringThe agent ID
versionintegerSpecific version to use. Omit for latest. Must be ≥ 1.

Request Examples

python
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-sb-YOUR_KEY",
    base_url="https://api.sandbase.ai"
)

session = client.beta.sessions.create(
    agent="agent_01HqR2k7vXbZ9mNpL3wYcT8f",
    environment_id="env_01abc...",
)
print(session.id)
typescript
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  apiKey: 'sk-sb-YOUR_KEY',
  baseURL: 'https://api.sandbase.ai',
});

const session = await client.beta.sessions.create({
  agent: 'agent_01HqR2k7vXbZ9mNpL3wYcT8f',
  environment_id: 'env_01abc...',
});
console.log(session.id);
bash
curl -X POST https://api.sandbase.ai/v1/sessions \
  -H "Authorization: Bearer sk-sb-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "agent_01HqR2k7vXbZ9mNpL3wYcT8f",
    "environment_id": "env_01abc..."
  }'

Response

Returns a Session object.

json
{
  "id": "sess_01abc...",
  "type": "session",
  "status": "idle",
  "title": null,
  "agent_id": "agent_01HqR2k7vXbZ9mNpL3wYcT8f",
  "agent_version": 1,
  "environment_id": "env_01abc...",
  "usage": null,
  "metadata": {},
  "archived_at": null,
  "created_at": "2026-05-29T10:00:00Z",
  "updated_at": "2026-05-29T10:00:00Z"
}

Session Object

FieldTypeDescription
idstringUnique session identifier (sess_...)
typestringAlways "session"
statusstringCurrent status: idle, running, rescheduling, terminated
titlestring | nullHuman-readable title
agent_idstringID of the agent this session runs
agent_versioninteger | nullPinned agent version (resolved at creation)
environment_idstringEnvironment this session runs in
usageobject | nullCumulative token usage. null until the first turn completes.
metadataobjectUser-defined key-value pairs
archived_atstring | nullRFC 3339 timestamp when archived
created_atstringRFC 3339 timestamp
updated_atstringRFC 3339 timestamp

Status Values

StatusDescription
idleWaiting for input. Ready to receive events.
runningAgent is actively executing (processing message, calling tools).
reschedulingTransient error occurred, retrying automatically.
terminatedUnrecoverable error. Session has ended.

Agent Reference

The session references its agent by agent_id and the resolved agent_version. To fetch the full agent configuration, call Get Agent with ?version={agent_version}.

Difference from Claude

Claude embeds a full resolved agent snapshot object inside the session. SandBase currently returns agent_id + agent_version references instead — fetch the agent separately if you need its configuration. A future release may embed the snapshot.

Usage Object

usage is null until the first turn completes, then holds cumulative token counts:

json
{ "input_tokens": 4520, "output_tokens": 1830 }

Roadmap

Claude's Session object also includes stats, resources, outcome_evaluations, vault_ids, and a richer usage (cache breakdown). These are not yet returned by SandBase and will be added in later phases. Clients should tolerate their absence.

Errors

StatusTypeDescription
400invalid_requestMissing required fields or invalid format
401authentication_errorInvalid or missing API key
404not_foundAgent or environment not found
403forbiddenAgent is archived