Implementation:Openai Openai node ChatKit Resource
| Knowledge Sources | |
|---|---|
| Domains | SDK, Beta, ChatKit |
| Last Updated | 2026-02-15 12:00 GMT |
Overview
The ChatKit resource class serves as a namespace that groups together the sessions and threads sub-resources for the OpenAI ChatKit beta feature.
Description
The ChatKit class extends APIResource and organizes two sub-resources: Sessions (for creating and managing ChatKit sessions) and Threads (for managing conversation threads within ChatKit). It does not define any API methods directly; all functionality is accessed through its child sub-resources.
The class also defines and exports the ChatKitWorkflow interface, which represents workflow metadata and state for a ChatKit session. This interface includes the workflow id, optional state_variables (key-value pairs for overriding workflow state), tracing settings (with an enabled boolean), and an optional version field for pinning to a specific workflow version.
The file re-exports numerous types from the threads sub-module including ChatSession, ChatKitThread, ChatKitAttachment, and various configuration parameter types that define the shape of ChatKit sessions and thread items.
Usage
Use the ChatKit resource when building chat-based applications that leverage the OpenAI ChatKit beta. Access it via client.beta.chatkit, then use .sessions to create and manage sessions or .threads to list and manage conversation threads.
Code Reference
Source Location
- Repository: openai-node
- File: src/resources/beta/chatkit/chatkit.ts
Signature
export class ChatKit extends APIResource {
sessions: SessionsAPI.Sessions;
threads: ThreadsAPI.Threads;
}
export interface ChatKitWorkflow {
id: string;
state_variables: { [key: string]: string | boolean | number } | null;
tracing: ChatKitWorkflow.Tracing;
version: string | null;
}
export namespace ChatKitWorkflow {
export interface Tracing {
enabled: boolean;
}
}
Import
import OpenAI from 'openai';
I/O Contract
Inputs
The ChatKit class itself does not accept direct inputs. It delegates to its sub-resources:
| Sub-Resource | Access Path | Description |
|---|---|---|
| Sessions | client.beta.chatkit.sessions |
Create and cancel ChatKit sessions |
| Threads | client.beta.chatkit.threads |
List and manage ChatKit conversation threads |
Outputs
| Name | Type | Description |
|---|---|---|
| ChatKitWorkflow | ChatKitWorkflow |
Workflow metadata including id, state variables, tracing, and version |
| ChatKitWorkflow.Tracing | { enabled: boolean } |
Tracing configuration for the workflow |
Usage Examples
import OpenAI from 'openai';
const client = new OpenAI();
// Create a ChatKit session
const session = await client.beta.chatkit.sessions.create({
user: 'user_123',
workflow: { id: 'my-workflow-id' },
});
// List ChatKit threads
const threads = await client.beta.chatkit.threads.list();
// Access workflow metadata from a session
console.log(session.workflow.id);
console.log(session.workflow.tracing.enabled);