> ## 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 code autocomplete

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}
  from openai import OpenAI

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

  for chunk in client.completions.create(
          model="meta-llama/Meta-Llama-3.1-70B-Instruct",
          prompt="Say my name",
          max_tokens=7,
          temperature=0,
          stream=True
  ):
      print(chunk.choices[0].text)
  ```

  ```bash cURL theme={null}
  curl 'https://api.tokenfactory.nebius.com/v1/completions' \
    -H "Content-Type: application/json" \
    -H "Authorization: $NEBIUS_API_KEY" \
    -d '{
      "model": "meta-llama/Meta-Llama-3.1-70B-Instruct"
      "prompt": "Say my name",
      "max_tokens": 7,
      "temperature": 0,
      "stream": true
    }'
  ```

  ```javascript JavaScript theme={null}
  import OpenAI from "openai";

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

  async function main() {
    const stream = await openai.completions.create({
      model: "meta-llama/Meta-Llama-3.1-70B-Instruct",
      prompt: "Say my name",
      stream: true,
    });

    for await (const chunk of stream) {
      console.log(chunk.choices[0].text);
    }
  }

  main();
  ```
</CodeGroup>

<Accordion title="Response">
  ```
  {
    "id": "cmpl-7iA7iJjj8V2zOkCGvWF2hAkDWBQZe",
    "object": "text_completion",
    "created": 1690759111,
    "choices": [
      {
        "text": "Heisenberg",
        "index": 0,
        "logprobs": null,
        "finish_reason": null
      }
    ],
    "model": "meta-llama/Meta-Llama-3.1-70B-Instruct",
    "system_fingerprint": "fp_44709d6aaa"
  }
  ```
</Accordion>

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