---
title: "What are stop sequences? The stop parameter in LLM APIs"
description: "Stop sequences are strings that end generation as soon as the model writes them. How the stop and stop_sequences parameters work, their limits, and when to use them."
url: https://broadrouter.com/glossary/stop-sequences/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Stop sequences

Updated 2026-11-16

Stop sequences are strings you send with a request that make the model stop generating as soon as it produces one of them. OpenAI calls the field stop and accepts up to 4 sequences; Anthropic calls it stop\_sequences. The matched text is normally left out of the returned output.

Also called: stop sequence, stop parameter, stop strings, stop\_sequences

Sometimes you know exactly where an answer should end. A stop sequence tells the server to cut generation there instead of paying for tokens you will throw away.

## How it works

You pass one or more strings. After each new [token](https://broadrouter.com/glossary/token/), the server checks whether the output now contains one of them. If it does, generation ends.

```json
{
  "model": "broadnet/gemma-4-26b-a4b",
  "messages": [{"role": "user", "content": "List three fruits, one per line, then write END."}],
  "stop": ["END"]
}
```

Provider details from the sources:

| Provider | Field | Notes |
| --- | --- | --- |
| OpenAI Chat Completions | `stop` | “Up to 4 sequences”; the reference still says “Not supported with latest reasoning models o3 and o4-mini” (wording as of 2026-11-16) |
| Anthropic Messages | `stop_sequences` | Response has `stop_reason: "stop_sequence"` and names the match in `stop_sequence` |
| vLLM (open-model servers) | `stop` | “String(s) that stop the generation when they are generated”; output excludes them |

In the OpenAI format a matched stop sequence reports [finish\_reason](https://broadrouter.com/glossary/finish-reason/) `stop`, the same value as a natural end. Anthropic separates the two.

## Why it matters

-   **Cost and latency.** Output tokens are billed and are slow to generate. Stopping at a known marker saves both.
-   **Format control.** Few-shot prompts often use a delimiter such as `###` between examples. A stop on that delimiter stops the model from writing the next example itself.
-   **Limits.** A stop sequence cannot shape what comes before the cut. For machine-readable output, [structured output](https://broadrouter.com/glossary/structured-output/) is the stronger tool. Keep [max\_tokens](https://broadrouter.com/glossary/max-tokens/) as the hard ceiling.

## On BroadNet Inference

BroadNet’s [API reference](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=glossary-stop-sequences&utm_content=body) does not document `stop`. Test it before relying on it: send a prompt that should hit your marker and check whether the reply ends there. As a fallback, cut the text in your client at the first marker; in a [stream](https://broadrouter.com/glossary/streaming/) you can also close the reader once the marker appears. Reasoning models on BroadNet (DeepSeek V4.1 Flash, GLM 5.3 and Qwen3.8 27B) think before they answer, so test whether a stop string can match inside the reasoning. The [migration walkthrough](https://broadrouter.com/blog/migrate-from-openai-api-code-walkthrough/) lists other OpenAI fields to check.

## Common mistakes

-   Choosing a stop string that can appear in normal output, such as a newline or a common word.
-   Assuming the stop string comes back in the reply and parsing for it.

## Questions

### How many stop sequences can I send?

OpenAI's reference allows up to 4 sequences in stop. Other providers set their own limits, so check their reference.

### Is the stop sequence included in the reply?

Usually not. vLLM's documentation says the returned output excludes the stop string. Anthropic returns which sequence fired in a separate stop\_sequence field.

### Does BroadNet Inference support stop?

BroadNet's API reference does not document stop. Test it on your model before relying on it, and keep a client-side cut as a backup.

## See also

-   [finish\_reason](https://broadrouter.com/glossary/finish-reason/) (term)
-   [max\_tokens](https://broadrouter.com/glossary/max-tokens/) (term)
-   [Chat Completions API](https://broadrouter.com/glossary/chat-completions-api/) (term)
-   [Structured output](https://broadrouter.com/glossary/structured-output/) (term)
-   [Token](https://broadrouter.com/glossary/token/) (term)
-   [Frequency and presence penalty](https://broadrouter.com/glossary/frequency-and-presence-penalty/) (term)
-   [Use the OpenAI Python SDK with BroadNet Inference](https://broadrouter.com/guides/openai-python-sdk/) (guide)
-   [Migrating off the OpenAI API: a code walkthrough in Python, Node, cURL](https://broadrouter.com/blog/migrate-from-openai-api-code-walkthrough/) (article)
-   [LLM streaming explained: SSE chunks, deltas, usage and cancel](https://broadrouter.com/blog/llm-streaming-sse-explained/) (article)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=glossary-stop-sequences&utm_content=page-cta) ·

**Sources**

-   [OpenAI API reference, create chat completion (stop) (checked 2026-11-16)](https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create)
-   [Anthropic docs, handling stop reasons (stop\_sequences) (checked 2026-11-15)](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons)
-   [vLLM documentation, SamplingParams (stop) (checked 2026-11-15)](https://docs.vllm.ai/en/latest/api/vllm/sampling_params/)
