TypeScript SDKReference

Chat Types

TypeScript types for OpenAI-compatible chat completions, including messages, tools, and streaming.

See Chat for usage.

ChatCompletionMessageParam

type ChatCompletionMessageParam =
  | ChatCompletionSystemMessageParam
  | ChatCompletionUserMessageParam
  | ChatCompletionAssistantMessageParam
  | ChatCompletionToolMessageParam
  | ChatCompletionFunctionMessageParam // deprecated

Union of all message role types.


ChatCompletionSystemMessageParam

interface ChatCompletionSystemMessageParam {
  role: 'system';
  content: string;
  name?: string;
}
FieldTypeDescription
role'system'Always 'system'.
contentstringSystem instruction.
namestringOptional participant name.

ChatCompletionUserMessageParam

interface ChatCompletionUserMessageParam {
  role: 'user';
  content: string | ContentPart[];
  name?: string;
}
FieldTypeDescription
role'user'Always 'user'.
contentstring | ContentPart[]Text or multi-part (text + image). See Vision.
namestringOptional participant name.

ChatCompletionAssistantMessageParam

interface ChatCompletionAssistantMessageParam {
  role: 'assistant';
  content: string | null;
  name?: string;
  refusal?: string | null;
  tool_calls?: ChatCompletionMessageToolCall[];
}
FieldTypeDescription
role'assistant'Always 'assistant'.
contentstring | nullReply content.
namestringOptional name.
refusalstring | nullRefusal message.
tool_callsChatCompletionMessageToolCall[]Tool calls. See Tool Calling.

ChatCompletionToolMessageParam

interface ChatCompletionToolMessageParam {
  role: 'tool';
  content: string;
  tool_call_id: string;
}
FieldTypeDescription
role'tool'Always 'tool'.
contentstringTool result (JSON string).
tool_call_idstringID from the tool call.

ChatCompletionTool

interface ChatCompletionTool {
  type: 'function';
  function: {
    name: string;
    description?: string;
    parameters?: Record<string, any>; // JSON Schema
    strict?: boolean;
  };
}
FieldTypeDescription
type'function'Always 'function'.
function.namestringFunction name.
function.descriptionstringFunction description.
function.parametersRecord<string, any>JSON Schema for parameters.
function.strictbooleanStrict schema enforcement.

ChatCompletionToolChoiceOption

type ChatCompletionToolChoiceOption =
  | 'none' 
  | 'auto' 
  | 'required'
  | { type: 'function'; function: { name: string } }

ChatCompletionMessageToolCall

interface ChatCompletionMessageToolCall {
  id: string;
  type: 'function';
  function: {
    name: string;
    arguments: string; // JSON-encoded
  };
}
FieldTypeDescription
idstringTool call ID.
type'function'Always 'function'.
function.namestringFunction name.
function.argumentsstringJSON-encoded arguments.

ChatCompletionCreateParams

type ChatCompletionCreateParams =
  | ChatCompletionCreateParamsNonStreaming  // stream?: false
  | ChatCompletionCreateParamsStreaming     // stream: true

interface ChatCompletionCreateParamsBase {
  model: string;
  messages: ChatCompletionMessageParam[];
  max_tokens?: number;
  temperature?: number;
  top_p?: number;
  n?: number;
  stop?: string | string[] | null;
  presence_penalty?: number;
  frequency_penalty?: number;
  logprobs?: boolean | null;
  top_logprobs?: number | null;
  user?: string;
  tools?: ChatCompletionTool[];
  tool_choice?: ChatCompletionToolChoiceOption;
  parallel_tool_calls?: boolean;
}
ParameterTypeDescription
modelstringModel slug. Browse models in the catalog.
messagesChatCompletionMessageParam[]Conversation history.
max_tokensnumberMax completion tokens.
temperaturenumberSampling temperature (0–2).
top_pnumberNucleus sampling.
nnumberNumber of choices.
stopstring | string[]Stop sequences.
presence_penaltynumberPresence penalty (−2 to 2).
frequency_penaltynumberFrequency penalty (−2 to 2).
logprobsbooleanInclude log probabilities.
top_logprobsnumberTop N logprobs per token.
userstringEnd-user identifier.
toolsChatCompletionTool[]Tool definitions.
tool_choiceChatCompletionToolChoiceOptionTool invocation mode.
parallel_tool_callsbooleanAllow parallel tool calls.

ChatCompletion

Returned by client.chat.completions.create() from POST /v1/chat/completions. This TypeScript interface matches the OpenAI Chat Completions API response exactly — the SDK performs no transformations.

interface ChatCompletion {
  id: string;
  object: 'chat.completion';
  created: number;
  model: string;
  choices: ChatCompletionChoice[];
  usage: CompletionUsage;
  system_fingerprint: string;
  prompt_filter_results: PromptFilterResult[];
}
FieldTypeDescription
idstringCompletion ID.
object'chat.completion'Object type.
creatednumberUnix timestamp.
modelstringModel used.
choicesChatCompletionChoice[]Completion choices.
usageCompletionUsageToken usage.
system_fingerprintstringSystem fingerprint.
prompt_filter_resultsPromptFilterResult[]Safety filter results for prompts. See Safety.

ChatCompletionChoice

interface ChatCompletionChoice {
  index: number;
  message: ChatCompletionMessage;
  finish_reason: string;
  logprobs: unknown;
  content_filter_results: ChoiceContentFilterResults;
}
FieldTypeDescription
indexnumberChoice index.
messageChatCompletionMessagerole, content, tool_calls, refusal.
finish_reasonstring'stop' · 'length' · 'content_filter' · 'tool_calls' · null.
logprobsunknownLog probability data.
content_filter_resultsChoiceContentFilterResultsPer-category filter results.

ChatCompletionChunk

interface ChatCompletionChunk {
  id: string;
  object: 'chat.completion.chunk';
  created: number;
  model: string;
  choices: ChatCompletionChunkChoice[];
  usage: CompletionUsage | null;
  prompt_filter_results: PromptFilterResult[];
}

Streamed via AsyncIterable<ChatCompletionChunk>. See Streaming.

FieldTypeDescription
idstringChunk ID (same for all chunks in one completion).
object'chat.completion.chunk'Object type.
creatednumberUnix timestamp.
modelstringModel used.
choicesChatCompletionChunkChoice[]Chunk choices with delta.
usageCompletionUsage | nullToken usage (only on final chunk).
prompt_filter_resultsPromptFilterResult[]Safety filter results.

CompletionUsage

interface CompletionUsage {
  prompt_tokens: number;
  completion_tokens: number;
  total_tokens: number;
  completion_tokens_details: CompletionTokensDetails;
  prompt_tokens_details: PromptTokensDetails;
}
FieldTypeDescription
prompt_tokensnumberInput tokens.
completion_tokensnumberOutput tokens.
total_tokensnumberTotal tokens.
completion_tokens_detailsCompletionTokensDetailsaccepted_prediction_tokens, audio_tokens, reasoning_tokens, rejected_prediction_tokens.
prompt_tokens_detailsPromptTokensDetailsaudio_tokens, cached_tokens.

How is this guide?

On this page