---
title: "Open an agent session"
method: POST
path: "/v2/agent/session"
tags: ["agent"]
---

# Open an agent session

`POST /v2/agent/session`

## Request

- Base URL: `https://api.cardog.app`
- URL: `https://api.cardog.app/v2/agent/session`
- Auth: one of:
  - API key in header `x-api-key`
  - HTTP bearer

Creates a short-lived session for the Cardog agent. Its `token` is a signed grant that says who the agent acts as, which tools it may use and which account pays for each turn. Pass `token` as the `grant` query parameter when you open the agent's socket. It expires after 120 seconds, so create a new one for every connection.

The kind of session follows the credential you send: a signed-in session opens a personal session, an API key opens one billed to that key, an anonymous session opens an anonymous one, and an organization token from an organization workspace opens an organization session. An organization API key, or a server with no person behind it, is a 403.

Costs 0 credits. Each agent turn is billed; the data the agent reads during a turn is not.

## Request body

- AgentSessionCreateRequest
  - `surface` 'web' | 'org' | 'native' | 'mcp' | 'sdk': Where the session is opened from: "web" (the Cardog website), "org" (an organization workspace), "native" (the mobile app), "mcp" (an MCP server) or "sdk" (your own program, using an API key). Default "sdk".
  - `context` object: Session settings. `hidden` lists tools to hide, up to 64.
    - `hidden` string[]: Tools the person chose to hide. It can only hide tools; it never adds one the session may not use.
  - `orgToken` string: The org token from the organization workspace, a short-lived credential tied to your membership. Send it to open an organization session; leave it out for a personal one.

## Response `200`

The session and its token

- AgentSession
  - `token` string, required: The signed session. Send it as the `grant` query parameter when you open the agent socket, or in the `X-Cardog-Agent-Grant` header when you read threads. It expires after 120 seconds: create a new session on every connect.
  - `grant` object, required: What the session may do and who pays, as signed into `token`
    - `sub` string, required: The account the session acts as. Every tool call in a turn runs as this account.
    - `kind` 'anonymous' | 'user' | 'org' | 'key', required: Who the session is for. "anonymous": a visitor with no account yet. "user": a signed-in person. "org": a member working in an organization workspace, created only from an org token. "key": the owner of a personal API key.
    - `class` string: The kind of organization ("oem", "gov", "dealer", "insurer", "fleet", "internal"), or "technician" for a technician's session. Present when `kind` is "org".
    - `role` string: The member's role when the session was created. Present when `kind` is "org".
    - `tenantId` string: The organization's account key. Present when `kind` is "org".
    - `orgId` string: The organization ID. Present when `kind` is "org".
    - `orgSlug` string: The workspace name used in the organization's URL. Present when `kind` is "org".
    - `orgName` string: The organization's name to show. Present when `kind` is "org".
    - `scopes` string[], required: The groups of tools the session may use, e.g. ["consumer"] or ["org:*", "org:oem"]. Tools outside them are not offered at all.
    - `credit` object, required: Where the credits for each turn come from. Tool calls inside a turn are not charged separately.
      - `channel` 'session' | 'key' | 'org', required: Who pays for each turn. "session": the person's own account (an anonymous session has no credits and is capped at a number of turns). "key": the API key the session was opened with. "org": the organization.
      - `ref` string, required: The account charged: the user ID for `session`, the key ID for `key`, the organization ID for `org`
    - `model` 'default' | 'fixture', required: The model the session runs on. "default": the normal model. "fixture": a scripted test model that answers every tool from a recorded example and reaches no live model or data.
    - `exp` integer, required: When the session expires, in seconds since the Unix epoch. Sessions last 120 seconds.
  - `surface` 'web' | 'org' | 'native' | 'mcp' | 'sdk', required: Where the session is opened from: "web" (the Cardog website), "org" (an organization workspace), "native" (the mobile app), "mcp" (an MCP server) or "sdk" (your own program, using an API key). Default "sdk".
  - `context` object, required: The session settings
    - `hidden` string[], required: Tools the person chose to hide. It can only hide tools; it never adds one the session may not use.
  - `expiresAt` string, date-time, required: When the session expires, ISO 8601
  - `socket` string, required: The path of the agent socket. Open it with `?grant={token}` on the same host as this API.
  - `links` object, required: `self`: this endpoint. `threads`: the session's past chats, when it has any.

## Other responses

- `400`: The request is invalid. The error response names each bad value in `refs` or `details` and, where it can, suggests the nearest valid ref in `suggestions`. We never fall back to a fuzzy match.
- `401`: No valid API key or session
- `403`: Your credential cannot use this endpoint (`forbidden`)
- `429`: Per-minute rate limit exceeded
- `500`: Internal error
- `503`: Temporarily unavailable (`unavailable`); retry with backoff

## Changes

- **2026-11-04** `0b43ff0bb604`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/cardog/apis/cardog-api-v2/changes/v2/agent/session/post.md)

---

[API](https://skmtc.dev/cardog/apis/cardog-api-v2.md) - [All operations](https://skmtc.dev/cardog/apis/cardog-api-v2/llms.txt) - [OpenAPI document](https://skmtc.dev/cardog/apis/cardog-api-v2/revisions/016058226dc5?raw)
