Skip to content

Chat Completions

POST /v1/chat/completions

Create a chat completion. Supports both streaming and non-streaming responses.

Request

Terminal window
curl https://ghostmind.optdmsa.com/v1/chat/completions \
-H "Authorization: Bearer sk-gm-..." \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"stream": false,
"temperature": 0.7,
"max_tokens": 1000
}'

Parameters

FieldTypeRequiredDefaultDescription
modelstringYesModel identifier. Use auto for automatic routing.
messagesarrayYesArray of {role, content} objects.
streambooleanNofalseEnable SSE streaming.
temperaturefloatNo1.0Sampling temperature (0-2).
max_tokensintNoMaximum tokens to generate.
conversation_idstringNoUUID for conversation continuity.
project_idstringNoUUID for project-native conversation.

Response (Non-Streaming)

{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"model": "auto",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 10,
"total_tokens": 30
}
}

Response (Streaming)

When stream: true, the response is Server-Sent Events:

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"}}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":"!"}}]}
data: [DONE]

See Streaming for detailed SSE documentation.

Conversation Continuity

To continue a conversation:

  1. First request: Omit conversation_id — a new conversation is created
  2. The response includes a conversation_id (in headers or metadata)
  3. Pass that conversation_id in subsequent requests

Project Conversations

To start a project-native conversation:

  1. Pass a project_id parameter
  2. The AI has access to project files from the first message
  3. The conversation is permanently linked to that project

Errors

StatusError TypeCause
401invalid_api_keyMissing or invalid API key
429rate_limit_exceededRate limit hit
503provider_unavailableNo healthy upstream session
503shutting_downServer is shutting down

Next Steps