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

# Text generation

For the following example to work, save your [API key](https://docs.tokenfactory.nebius.com/api-reference/introduction#authentication) to the `NEBIUS_API_KEY` environment variable.

Here is a sample JSON request body that includes all supported fields:

<CodeGroup>
  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.tokenfactory.nebius.com/v1/",
      api_key=os.environ.get("NEBIUS_API_KEY"),
  )

  completion = client.chat.completions.create(
      model="meta-llama/Meta-Llama-3.1-70B-Instruct",
      messages=[
          {
            "role": "system",
            "content": "You are a chemistry expert. Add jokes about cats to your responses from time to time."
          },
          {
            "role": "user",
            "content": "Hello!"
          },
          {
            "role": "assistant",
            "content": "Hello! How can I assist you with chemistry today? And did you hear about the cat who became a chemist? She had nine lives, but she only needed one formula!"
          }
      ],
      max_tokens=100,
      temperature=1,
      top_p=1,
      top_k=50,
      n=1,
      stream=false,
      stream_options=null,
      stop=null,
      presence_penalty=0,
      frequency_penalty=0,
      logit_bias=null,
      logprobs=false,
      top_logprobs=null,
      user=null,
      extra_body={
          "guided_json": {"type": "object", "properties": {...}}
      },
      response_format={
          "type": "json_object"
      }
  )

  print(completion.to_json())
  ```

  ```bash cURL theme={null}
  curl 'https://api.tokenfactory.nebius.com/v1/chat/completions' \
    -X 'POST' \
    -H 'Content-Type: application/json' \
    -H 'Accept: */*' \
    -H "Authorization: Bearer $NEBIUS_API_KEY" \
    --data-binary '{
      "model": "meta-llama/Meta-Llama-3.1-70B-Instruct",
      "messages": [
        {
          "role": "system",
          "content": "You are a chemistry expert. Add jokes about cats to your responses from time to time."
        },
        {
          "role": "user",
          "content": "Hello!"
        },
        {
          "role": "assistant",
          "content": "Hello! How can I assist you with chemistry today? And did you hear about the cat who became a chemist? She had nine lives, but she only needed one formula!"
        }
      ],
      "max_tokens": 100,
      "temperature": 1,
      "top_p": 1,
      "top_k": 50,
      "n": 1,
      "stream": false,
      "stream_options": null,
      "stop": null,
      "presence_penalty": 0,
      "frequency_penalty": 0,
      "logit_bias": null,
      "logprobs": false,
      "top_logprobs": null,
      "user": null,
      "guided_json": {"type": "object", "properties": {...}}
      "response_format": {"type": "json_object"}
    }'
  ```

  ```javascript JavaScript theme={null}
  const OpenAI = require("openai");

  const client = new OpenAI({
    baseURL: "https://api.tokenfactory.nebius.com/v1/",
    apiKey: process.env.NEBIUS_API_KEY,
  });

  client.chat.completions.create({
    "max_tokens": 100,
    "temperature": 1,
    "top_p": 1,
    "top_k": 50,
    "n": 1,
    "stream": false,
    "stream_options": null,
    "stop": null,
    "presence_penalty": 0,
    "frequency_penalty": 0,
    "logit_bias": null,
    "logprobs": false,
    "top_logprobs": null,
    "user": null,
    "extra_body": {
      "guided_json": {"type": "object", "properties": {...},}
    },
    "response_format": {
      "type": "json_object"
    },
    "model": "meta-llama/Meta-Llama-3.1-70B-Instruct",
    "messages": [
      {
        "role": "system",
        "content": "You are a chemistry expert. Add jokes about cats to your responses from time to time."
      },
      {
        "role": "user",
        "content": "Hello!"
      },
      {
        "role": "assistant",
        "content": "Hello! How can I assist you with chemistry today? And did you hear about the cat who became a chemist? She had nine lives, but she only needed one formula!"
      }
    ]
  })
  .then((completion) => console.log(completion));
  ```
</CodeGroup>

<Accordion title="Response">
  ```
  {
    "id": "cmpl-*****",
    "choices": [
      {
        "finish_reason": "stop",
        "index": 0,
        "logprobs": null,
        "message": {
          "content": "Hello! It's nice to meet you. Is there something I can help you with, or would you like to chat?",
          "role": "assistant",
          "function_call": null,
          "tool_calls": []
        },
        "stop_reason": null
      }
    ],
    "created": 1721397089,
    "model": "meta-llama/Meta-Llama-3.1-70B-Instruct",
    "object": "chat.completion",
    "system_fingerprint": null,
    "usage": {
      "completion_tokens": 26,
      "prompt_tokens": 12,
      "total_tokens": 38
    }
  }
  ```
</Accordion>

For detailed field descriptions, see the [API reference](https://docs.tokenfactory.nebius.com/api-reference/introduction).
