> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yelu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat example

> Build a complete non-streaming chat request and read assistant text and token usage.

This example sends system and user messages, checks the HTTP result, and reads the assistant content and usage.

<CodeGroup>
  ```bash Curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -sS https://api.yelu.ai/v1/chat/completions \
    -H "Authorization: Bearer $YELU_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4o-mini",
      "messages": [
        {"role":"system","content":"You explain technical concepts with one analogy."},
        {"role":"user","content":"What is an embedding?"}
      ],
      "temperature": 0.3,
      "max_completion_tokens": 180
    }' | jq '{text: .choices[0].message.content, usage: .usage}'
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  async function chat(question) {
    const response = await fetch('https://api.yelu.ai/v1/chat/completions', {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${process.env.YELU_API_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        model: 'gpt-4o-mini',
        messages: [
          { role: 'system', content: 'You explain technical concepts with one analogy.' },
          { role: 'user', content: question },
        ],
        temperature: 0.3,
        max_completion_tokens: 180,
      }),
    });
    if (!response.ok) throw new Error(await response.text());
    const data = await response.json();
    return { text: data.choices[0].message.content, usage: data.usage };
  }

  console.log(await chat('What is an embedding?'));
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  import requests

  def chat(question):
      response = requests.post(
          "https://api.yelu.ai/v1/chat/completions",
          headers={"Authorization": f"Bearer {os.environ['YELU_API_KEY']}"},
          json={
              "model": "gpt-4o-mini",
              "messages": [
                  {"role": "system", "content": "You explain technical concepts with one analogy."},
                  {"role": "user", "content": question},
              ],
              "temperature": 0.3,
              "max_completion_tokens": 180,
          },
          timeout=60,
      )
      response.raise_for_status()
      data = response.json()
      return {"text": data["choices"][0]["message"]["content"], "usage": data.get("usage")}

  print(chat("What is an embedding?"))
  ```
</CodeGroup>

## Extend the conversation

Append the assistant message and the next user message to the `messages` array. Your application owns Chat Completions history; trim or summarize it before the model's context limit, and keep the original system policy.

<Tip>
  For server-managed continuation on compatible routes, consider the [Responses API](/en/api-reference/responses). Still persist the state your product needs for auditability and recovery.
</Tip>
