تخطَّ إلى المحتوى

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 gmk_live_..." \
-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
modelstringYes—Model identifier. Use auto for automatic routing.
messagesarrayYes—Array of {role, content} objects.
streambooleanNofalseEnable SSE streaming.
attachment_file_idsarrayNo—file_ids from POST /v1/conversations/{id}/attachments to attach files.
temperaturefloatNo—Accepted but ignored (ChatGPT does not expose it).
top_pfloatNo—Accepted but ignored.
max_tokensintNo—Accepted but ignored.

Rejected parameters (400 UNSUPPORTED_PARAMETER): tools, tool_choice, n>1, logprobs.

NOT supported as body fields (unknown fields are silently ignored — extra: ignore): conversation_id, project_id. Use the routing headers or POST /v1/conversations instead — see below.

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

Continuity is header-based — there is NO conversation_id body field:

  1. First request: send no conversation header — a new conversation is created
  2. Read the X-GhostMind-Conversation-Id response header
  3. Pass X-GhostMind-Conversation-Id: <id> as a request header on subsequent calls (or create the conversation up front via POST /v1/conversations and use its id)

A request with no routing lands in the account’s general space — GhostMind does not create an upstream project per request by default.

Project Conversations

Projects from POST /v1/projects are upstream projects. Either:

  1. Create the conversation with POST /v1/conversations {"upstream_project_id": "<uuid>"} and continue via X-GhostMind-Conversation-Id, or
  2. Route the request directly with X-GhostMind-Upstream-Project: <slug> (slug, not UUID)

The AI has access to project files from the first message, and 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