Skip to content

AI Chat API

Endpoints for executing AI chat completions, with support for both standard and streaming responses, and optional thread context.

SDK equivalent: sdk.ai.chat

Chat Completion

Execute a chat completion without thread context.

POST /api/ai/{integrationId}/chat-completion

Path Parameters

ParameterTypeDescription
integrationIdstringThe AI integration ID

Request Body

json
{
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Hello, how can you help me?" }
  ],
  "model": "gpt-4",
  "temperature": 0.7,
  "top_p": 0.9,
  "max_tokens": 500,
  "frequency_penalty": 0.1,
  "presence_penalty": 0.1,
  "stop": ["END"],
  "context": {
    "userId": "user-123"
  }
}
FieldTypeRequiredDescription
messagesIMessage[]YesArray of conversation messages
modelstringNoModel to use (defaults to integration setting)
temperaturenumberNoSampling temperature (0–2)
top_pnumberNoNucleus sampling parameter
max_tokensnumberNoMaximum tokens in the response
frequency_penaltynumberNoFrequency penalty (-2 to 2)
presence_penaltynumberNoPresence penalty (-2 to 2)
stopstring | string[]NoStop sequences
response_formatobjectNoResponse format specification
contextobjectNoAdditional context data
streambooleanNoSet to true for streaming response
clientToolsIClientTool[]NoClient-side tool definitions
rulesstring[]NoAdditional rules for the AI
queryParamsobjectNoAdditional query parameters

Message Format

json
{
  "role": "user | assistant | system | tool",
  "content": "Message text",
  "name": "optional-name",
  "tool_calls": [],
  "tool_call_id": "optional-tool-call-id"
}

Response

json
{
  "id": "completion-id",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "gpt-4",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! I can help you with..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 50,
    "total_tokens": 75
  }
}

SDK: sdk.ai.chat.chat(integrationId, options)


Chat Completion in Thread

Execute a chat completion within a thread context. The thread's message history is automatically included.

POST /api/ai/{integrationId}/chat-completion/{threadId}

Path Parameters

ParameterTypeDescription
integrationIdstringThe AI integration ID
threadIdstringThe thread ID for context

Request Body

Same as Chat Completion.

Response

Same as Chat Completion. The new messages are automatically appended to the thread.

SDK: sdk.ai.chat.chatInThread(integrationId, threadId, options)


Streaming Chat Completion

Execute a streaming chat completion. Returns a Server-Sent Events (SSE) stream.

POST /api/ai/{integrationId}/chat-completion

Headers

HeaderValueDescription
Accepttext/event-streamRequired for streaming responses

Path Parameters

ParameterTypeDescription
integrationIdstringThe AI integration ID

Request Body

Same as Chat Completion, with stream set to true:

json
{
  "messages": [
    { "role": "user", "content": "Tell me a story" }
  ],
  "stream": true,
  "temperature": 0.8
}

Response

Returns a text/event-stream response. Each event contains a JSON chunk:

data: {"id":"completion-id","choices":[{"index":0,"delta":{"content":"Once"},"finish_reason":null}]}

data: {"id":"completion-id","choices":[{"index":0,"delta":{"content":" upon"},"finish_reason":null}]}

data: {"id":"completion-id","choices":[{"index":0,"delta":{"content":" a"},"finish_reason":null}]}

data: [DONE]

SDK: sdk.ai.chat.stream(integrationId, options)


Streaming Chat Completion in Thread

Execute a streaming chat completion with thread context.

POST /api/ai/{integrationId}/chat-completion/{threadId}

Headers

HeaderValueDescription
Accepttext/event-streamRequired for streaming responses

Path Parameters

ParameterTypeDescription
integrationIdstringThe AI integration ID
threadIdstringThe thread ID for context

Request Body

Same as Streaming Chat Completion.

Response

Returns a text/event-stream response (same format as streaming without thread).

SDK: sdk.ai.chat.streamInThread(integrationId, threadId, options)

Build SaaS Products Without Limits.