Skip to content
Primary navigation

Create ChatKit session

client.Beta.ChatKit.Sessions.New(ctx, body) (*ChatSession, error)
POST/chatkit/sessions

Create a ChatKit session.

ParametersExpand Collapse
body BetaChatKitSessionNewParams
User param.Field[string]

A free-form string that identifies your end user; ensures this Session can access other objects that have the same user scope.

minLength1
Workflow param.Field[ChatSessionWorkflowParamResp]

Workflow that powers the session.

ChatKitConfiguration param.Field[ChatSessionChatKitConfigurationParamResp]optional

Optional overrides for ChatKit runtime configuration features

ExpiresAfter param.Field[ChatSessionExpiresAfterParamResp]optional

Optional override for session expiration timing in seconds from creation. Defaults to 10 minutes.

RateLimits param.Field[ChatSessionRateLimitsParamResp]optional

Optional override for per-minute request limits. When omitted, defaults to 10.

ReturnsExpand Collapse
type ChatSession struct{…}

Represents a ChatKit session and its resolved configuration.

ID string

Identifier for the ChatKit session.

ChatKitConfiguration ChatSessionChatKitConfiguration

Resolved ChatKit feature configuration for the session.

AutomaticThreadTitling ChatSessionAutomaticThreadTitling

Automatic thread titling preferences.

Enabled bool

Whether automatic thread titling is enabled.

Upload settings for the session.

Enabled bool

Indicates if uploads are enabled for the session.

MaxFileSize int64

Maximum upload size in megabytes.

MaxFiles int64

Maximum number of uploads allowed during the session.

History retention configuration.

Enabled bool

Indicates if chat history is persisted for the session.

RecentThreads int64

Number of prior threads surfaced in history views. Defaults to null when all history is retained.

ClientSecret string

Ephemeral client secret that authenticates session requests.

ExpiresAt int64

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

MaxRequestsPer1Minute int64

Convenience copy of the per-minute request limit.

Object ChatKitSession

Type discriminator that is always chatkit.session.

Resolved rate limit values.

MaxRequestsPer1Minute int64

Maximum allowed requests per one-minute window.

Current lifecycle state of the session.

Accepts one of the following:
const ChatSessionStatusActive ChatSessionStatus = "active"
const ChatSessionStatusExpired ChatSessionStatus = "expired"
const ChatSessionStatusCancelled ChatSessionStatus = "cancelled"
User string

User identifier associated with the session.

Workflow metadata for the session.

ID string

Identifier of the workflow backing the session.

StateVariables map[string, ChatKitWorkflowStateVariableUnion]

State variable key-value pairs applied when invoking the workflow. Defaults to null when no overrides were provided.

Accepts one of the following:
string
bool
float64
Tracing ChatKitWorkflowTracing

Tracing settings applied to the workflow.

Enabled bool

Indicates whether tracing is enabled.

Version string

Specific workflow version used for the session. Defaults to null when using the latest deployment.

Create ChatKit session

package main

import (
  "context"
  "fmt"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/option"
)

func main() {
  client := openai.NewClient()
  chatSession, err := client.Beta.ChatKit.Sessions.New(context.TODO(), openai.BetaChatKitSessionNewParams{
    User: "user",
    Workflow: openai.ChatSessionWorkflowParam{
      ID: "id",
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", chatSession.ID)
}
{
  "client_secret": "chatkit_token_123",
  "expires_at": 1735689600,
  "workflow": {
    "id": "workflow_alpha",
    "version": "2024-10-01"
  },
  "scope": {
    "project": "alpha",
    "environment": "staging"
  },
  "max_requests_per_1_minute": 60,
  "max_requests_per_session": 500,
  "status": "active"
}
Returns Examples
{
  "client_secret": "chatkit_token_123",
  "expires_at": 1735689600,
  "workflow": {
    "id": "workflow_alpha",
    "version": "2024-10-01"
  },
  "scope": {
    "project": "alpha",
    "environment": "staging"
  },
  "max_requests_per_1_minute": 60,
  "max_requests_per_session": 500,
  "status": "active"
}