Skip to content

Chat Completion

Use the chat completion endpoint to drive multi-turn conversations, tool calls, or streaming assistants with stateful message histories.

Endpoint

  • Base URL: https://devnet.aimo.network/api/v1
  • POST /chat/completions
  • Requires Authorization: Bearer <API_KEY> header
  • Optional X-Request-ID to aid tracing and log correlation

Request Body

FieldTypeRequiredNotes
modelstringYesprovider_pubkey:model_name (e.g. 8W7X1tGnWh9CXwnPD7wgke31Gdcqmex4LapJvQ2afBUq:deepseek-chat-v3)
messagesarrayYesOpenAI-compatible role/content messages
toolsarrayNoDeclares tool definitions the model may call
tool_choicestring/objectNoForce a specific tool or allow the model to choose
temperaturenumberNoFloat between 0 and 2; defaults to 0.7
top_pnumberNoAlternative to temperature; defaults to 1
max_tokensintegerNoCaps completion length; provider default if omitted
streambooleanNoEnables server-sent events response
metadataobjectNoArbitrary key/value pairs forwarded to logs

Response

  • Returns id, created, and the selected model
  • choices array includes message text, tool calls, and finish reason
  • usage block reports input/output token counts
  • Streaming responses emit SSE data: payloads ending with [DONE]

Examples

Basic request

curl -X POST "https://devnet.aimo.network/api/v1/chat/completions" \
  -H "Authorization: Bearer aimo-sk-dev-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "8W7X1tGnWh9CXwnPD7wgke31Gdcqmex4LapJvQ2afBUq:deepseek-chat-v3",
    "messages": [
      {"role": "user", "content": "Explain quantum computing in one paragraph."}
    ],
    "max_tokens": 250,
    "temperature": 0.7
  }'
Sample response
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1718822400,
  "model": "8W7X1tGnWh9CXwnPD7wgke31Gdcqmex4LapJvQ2afBUq:deepseek-chat-v3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Quantum computing leverages..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 15,
    "completion_tokens": 72,
    "total_tokens": 87
  }
}

Streaming in JavaScript

const response = await fetch("https://devnet.aimo.network/api/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": "Bearer aimo-sk-dev-your-api-key",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "8W7X1tGnWh9CXwnPD7wgke31Gdcqmex4LapJvQ2afBUq:deepseek-chat-v3",
    messages: [
      { role: "user", content: "Tell me about blockchain technology." }
    ],
    stream: true
  })
});
 
const reader = response.body.getReader();
const decoder = new TextDecoder();
 
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  const chunk = decoder.decode(value);
  console.log(chunk); // Each chunk is an SSE frame such as "data: {...}" or "data: [DONE]"
}

Python example

import requests
 
url = "https://devnet.aimo.network/api/v1/chat/completions"
headers = {
    "Authorization": "Bearer aimo-sk-dev-your-api-key",
    "Content-Type": "application/json"
}
 
payload = {
    "model": "8W7X1tGnWh9CXwnPD7wgke31Gdcqmex4LapJvQ2afBUq:deepseek-chat-v3",
    "messages": [
        {"role": "user", "content": "What is machine learning?"}
    ],
    "stream": False,
    "max_tokens": 300
}
 
response = requests.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
print(response.json())

Error Codes

HTTP CodeMeaningGuidance
400Invalid payloadVerify schema and required fields
401UnauthorizedCheck token scope and expiry
429Rate limitSlow down or request higher quota
500Provider failureRetry with backoff or failover