POST /api/v1/playground/stream

Stream an LLM completion using a project's configured provider key. Used internally by the dashboard playground, but available to any authenticated client.

Request

POST /api/v1/playground/stream
Authorization: Bearer ts_...
Content-Type: application/json

{
  "model": "gpt-4o",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Explain quicksort in one paragraph." }
  ],
  "temperature": 0.7,
  "max_tokens": 500
}

Parameters

FieldTypeRequiredDescription
modelstringYesModel identifier (e.g., gpt-4o, claude-3-opus)
messagesarrayYesChat messages with role and content
temperaturenumberNoSampling temperature (0–2)
max_tokensnumberNoMaximum tokens to generate

Response

Returns a Server-Sent Events (SSE) stream. Each event contains a chunk of the completion:

event: token
data: {"content": "Quick"}

event: token
data: {"content": "sort"}

event: done
data: {"usage": {"prompt_tokens": 25, "completion_tokens": 150, "total_tokens": 175}}

Requirements

  • The project must have an LLM provider key configured for the requested model's provider.
  • Provider keys are managed via the llmKey tRPC router or the Project Settings page in the dashboard.

Errors

StatusMeaning
400Invalid request body or unsupported model
401Invalid API key
404No provider key configured for the requested model
429Rate limited
502LLM provider error (upstream failure)

Have questions? Join our community!

Connect with other developers and the 2Signal team.

Join Discord