Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Cancel a ChatKit session

beta.chatkit.sessions.cancel(strsession_id) -> ChatSession
POST/chatkit/sessions/{session_id}/cancel

Cancel an active ChatKit session and return its most recent metadata.

Cancelling prevents new requests from using the issued client secret.

ParametersExpand Collapse
session_id: str
ReturnsExpand Collapse
class ChatSession: …

Represents a ChatKit session and its resolved configuration.

id: str

Identifier for the ChatKit session.

chatkit_configuration: ChatSessionChatKitConfiguration

Resolved ChatKit feature configuration for the session.

client_secret: str

Ephemeral client secret that authenticates session requests.

expires_at: int

Unix timestamp (in seconds) for when the session expires.

formatunixtime
max_requests_per_1_minute: int

Convenience copy of the per-minute request limit.

object: Literal["chatkit.session"]

Type discriminator that is always chatkit.session.

Resolved rate limit values.

Current lifecycle state of the session.

user: str

User identifier associated with the session.

workflow: ChatKitWorkflow

Workflow metadata for the session.

Cancel a ChatKit session

from openai import OpenAI

client = OpenAI()
chat_session = client.beta.chatkit.sessions.cancel(
    "cksess_123",
)
print(chat_session.id)
{
  "id": "cksess_123",
  "object": "chatkit.session",
  "workflow": {
    "id": "workflow_alpha",
    "version": "1"
  },
  "scope": {
    "customer_id": "cust_456"
  },
  "max_requests_per_1_minute": 30,
  "ttl_seconds": 900,
  "status": "cancelled",
  "cancelled_at": 1712345678
}
Returns Examples
{
  "id": "cksess_123",
  "object": "chatkit.session",
  "workflow": {
    "id": "workflow_alpha",
    "version": "1"
  },
  "scope": {
    "customer_id": "cust_456"
  },
  "max_requests_per_1_minute": 30,
  "ttl_seconds": 900,
  "status": "cancelled",
  "cancelled_at": 1712345678
}