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

# Swytcho Completions API: Generate Text from a Prompt

> Use the Swytcho completions endpoint to generate text from a prompt. Control output length, creativity, and stopping behavior for any generation task.

The completions endpoint is the most direct way to generate text with Swytcho. You send a prompt, the model continues it, and you receive the generated text. This makes it ideal for structured generation tasks like writing product descriptions, summarizing documents, or producing formatted output in a single pass.

## Completions vs. Chat Completions

Before reaching for the completions endpoint, consider which interface fits your use case.

| Use Case                                    | Recommended Endpoint   |
| ------------------------------------------- | ---------------------- |
| Single-turn generation from a prompt        | `/v1/completions`      |
| Batch text production (summaries, rewrites) | `/v1/completions`      |
| Multi-turn conversation                     | `/v1/chat/completions` |
| Instruction-following with context          | `/v1/chat/completions` |

Use the completions endpoint when you have a raw prompt you want continued or completed. Use chat completions when your task is better expressed as a conversation with a system instruction.

## Send Your First Request

Make a `POST` request to `https://api.swytcho.com/v1/completions` with your model, prompt, and any generation parameters.

<CodeGroup>
  ```python Python theme={null}
  import os
  import requests

  response = requests.post(
      "https://api.swytcho.com/v1/completions",
      headers={
          "Authorization": f"Bearer {os.environ['SWYTCHO_API_KEY']}",
          "Content-Type": "application/json",
      },
      json={
          "model": "swytcho-1",
          "prompt": "Write a product description for a noise-cancelling travel headphone:",
          "max_tokens": 256,
          "temperature": 0.7,
      },
  )

  result = response.json()
  print(result["choices"][0]["text"])
  ```

  ```javascript Node.js theme={null}
  import fetch from "node-fetch";

  const response = await fetch("https://api.swytcho.com/v1/completions", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.SWYTCHO_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "swytcho-1",
      prompt: "Write a product description for a noise-cancelling travel headphone:",
      max_tokens: 256,
      temperature: 0.7,
    }),
  });

  const result = await response.json();
  console.log(result.choices[0].text);
  ```

  ```bash curl theme={null}
  curl https://api.swytcho.com/v1/completions \
    -H "Authorization: Bearer $SWYTCHO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "swytcho-1",
      "prompt": "Write a product description for a noise-cancelling travel headphone:",
      "max_tokens": 256,
      "temperature": 0.7
    }'
  ```
</CodeGroup>

## Key Parameters

### `prompt`

The text the model will continue. The quality and specificity of your prompt directly shapes the output. Include examples, formatting instructions, or constraints directly in the prompt string.

### `max_tokens`

The maximum number of tokens to generate. One token is roughly four characters of English text. Set this to a value that comfortably fits your expected output — the model stops as soon as it hits this limit or produces a natural stopping point.

### `temperature`

Controls the randomness of the output on a scale from `0` to `2`.

<Tip>
  Set `temperature` to `0` for fully deterministic, reproducible output — ideal for structured tasks like data extraction or classification. Raise it toward `1` or higher for creative writing, brainstorming, or variation-heavy tasks.
</Tip>

### `stop`

An array of up to four strings. The model halts generation as soon as it produces any of these sequences, and the stop string itself is not included in the output. Useful for trimming responses at a known boundary:

```json theme={null}
{
  "stop": ["\n\n", "###", "<END>"]
}
```

## Working with the Response

A successful response returns a JSON object. The generated text lives at `choices[0].text`.

```json theme={null}
{
  "id": "cmpl-abc123",
  "object": "text_completion",
  "model": "swytcho-1",
  "choices": [
    {
      "text": " Escape the noise on every journey. The AirZen Pro delivers...",
      "index": 0,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 14,
    "completion_tokens": 89,
    "total_tokens": 103
  }
}
```

Check `choices[0].finish_reason` to understand why generation stopped:

* `"stop"` — the model reached a natural end or a stop sequence
* `"length"` — the `max_tokens` limit was hit; consider increasing it if the output is cut off
* `"content_filter"` — the output was blocked by safety filters

Extract the text and handle each finish reason in your application:

```python Python theme={null}
result = response.json()
choice = result["choices"][0]

if choice["finish_reason"] == "length":
    print("Warning: output may be truncated")

print(choice["text"].strip())
```
