Examples

Code examples for common API operations. For complete endpoint documentation, see API Reference. For detailed streaming information, see Streaming.

curl

Non-streaming chat:

curl -X POST http://localhost:7000/v1/chat \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Hello!", "include_thinking": false}'

Streaming chat:

curl -N -X POST http://localhost:7000/v1/chat/stream \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Hello!", "include_thinking": true}'

Python

import requests

# Non-streaming
data = requests.post(
    'http://localhost:7000/v1/chat',
    json={'prompt': 'Hi there'}
).json()
print(data['response'])

# Streaming
resp = requests.post(
    'http://localhost:7000/v1/chat/stream',
    json={'prompt': 'Hi there'},
    stream=True,
)
for line in resp.iter_lines():
    if line.startswith(b'data: '):
        print(line[6:].decode())

JavaScript (fetch)

async function chat(prompt) {
  const res = await fetch('/api/chat', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ prompt })
  });
  const data = await res.json();
  console.log(data.response);
}

JavaScript (stream)

async function streamChat(prompt) {
  const res = await fetch('/api/chat/stream', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ prompt, include_thinking: true })
  });

  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  let buffer = '';

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    buffer += decoder.decode(value, { stream: true });
    const lines = buffer.split('\n');
    buffer = lines.pop();
    for (const line of lines) {
      if (line.startsWith('data: ')) {
        const event = JSON.parse(line.slice(6));
        if (event.type === 'token') console.log(event.content);
      }
    }
  }
}