Skip to content

Your First Request

Now that you have an API key, let’s make a real request and understand each part.

The Request

Terminal window
curl https://ghostmind.optdmsa.com/v1/chat/completions \
-H "Authorization: Bearer $GHOSTMIND_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in one sentence."}
],
"temperature": 0.7,
"max_tokens": 100
}'

Request Fields

FieldTypeRequiredDescription
modelstringYesModel identifier. Use auto for automatic routing.
messagesarrayYesArray of message objects with role and content.
temperaturefloatNoSampling temperature (0-2). Default: 1.0
max_tokensintNoMaximum tokens to generate.
streamboolNoEnable SSE streaming. Default: false
conversation_idstringNoUUID for conversation continuity.

Message Roles

RoleDescription
systemSets assistant behavior (optional, first message)
userUser input
assistantPrevious assistant response (for context)

The Response

{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1723190400,
"model": "auto",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Quantum computing harnesses quantum mechanical phenomena..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 18,
"total_tokens": 43
}
}

Response Fields

FieldDescription
idUnique completion ID
objectAlways chat.completion
modelModel used for this request
choicesArray of completion choices
choices[].finish_reasonstop, length, content_filter, or error
usageToken usage for this request

Conversation Continuity

To maintain context across multiple requests, pass a conversation_id:

  1. First request: Omit conversation_id — a new conversation is created
  2. Response: The response includes a conversation_id in the headers or body
  3. Follow-up: Pass that conversation_id in subsequent requests
Terminal window
# First message
curl https://ghostmind.optdmsa.com/v1/chat/completions \
-H "Authorization: Bearer $GHOSTMIND_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "auto", "messages": [{"role": "user", "content": "My name is Alice."}]}'
# Follow-up (use the conversation_id from the first response)
curl https://ghostmind.optdmsa.com/v1/chat/completions \
-H "Authorization: Bearer $GHOSTMIND_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"conversation_id": "conv-uuid-from-first-response",
"messages": [{"role": "user", "content": "What is my name?"}]
}'

Streaming

For real-time responses, set stream: true:

Terminal window
curl https://ghostmind.optdmsa.com/v1/chat/completions \
-H "Authorization: Bearer $GHOSTMIND_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"stream": true,
"messages": [{"role": "user", "content": "Tell me a story."}]
}'

See Streaming for detailed SSE format documentation.

Errors

If something goes wrong, you’ll receive an error response:

{
"error": {
"message": "No healthy upstream session available.",
"type": "provider_unavailable",
"code": "no_healthy_session"
}
}

See Errors for a complete reference.

Next Steps