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

# Completions

> Generate a text completion given a prompt.

## POST /v1/completions

Creates a completion for the given prompt and model.

### Request body

<ParamField body="model" type="string" required>
  The model ID to use. See the [models page](https://openinference.xyz/models) for available models.

  Example: `openai/gpt-oss-120b`
</ParamField>

<ParamField body="prompt" type="string" required>
  The prompt to generate a completion for.
</ParamField>

<ParamField body="max_tokens" type="integer">
  Maximum number of tokens to generate. Defaults to the model's maximum.
</ParamField>

<ParamField body="temperature" type="number">
  Sampling temperature between 0 and 2. Defaults to `1`.
</ParamField>

<ParamField body="top_p" type="number">
  Nucleus sampling parameter. Defaults to `1`.
</ParamField>

<ParamField body="stream" type="boolean">
  If `true`, responses are sent as server-sent events. Defaults to `false`.
</ParamField>

<ParamField body="stop" type="string | array">
  Up to 4 sequences where the model will stop generating.
</ParamField>

### Example request

<CodeGroup>
  ```bash curl theme={null}
  curl https://api.openinference.xyz/v1/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $OPENINFERENCE_API_KEY" \
    -d '{
      "model": "openai/gpt-oss-120b",
      "prompt": "The capital of France is",
      "max_tokens": 50
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.openinference.xyz/v1",
      api_key="your-api-key",
  )

  response = client.completions.create(
      model="openai/gpt-oss-120b",
      prompt="The capital of France is",
      max_tokens=50,
  )
  print(response.choices[0].text)
  ```
</CodeGroup>

### Example response

```json theme={null}
{
  "id": "cmpl-abc123",
  "object": "text_completion",
  "created": 1709000000,
  "model": "openai/gpt-oss-120b",
  "choices": [
    {
      "index": 0,
      "text": " Paris, which is also the largest city in France.",
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 7,
    "completion_tokens": 12,
    "total_tokens": 19
  }
}
```

### Streaming

Set `stream: true` to receive responses as server-sent events.

```bash theme={null}
curl https://api.openinference.xyz/v1/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENINFERENCE_API_KEY" \
  -d '{
    "model": "openai/gpt-oss-120b",
    "prompt": "Hello",
    "max_tokens": 50,
    "stream": true
  }'
```
