---
title: "Create a Text Completion"
method: POST
path: "/v1/complete"
---

# Create a Text Completion

`POST /v1/complete`

[Legacy] Create a Text Completion.

The Text Completions API is a legacy API. We recommend using the [Messages API](https://platform.claude.com/docs/en/api/messages) going forward.

Future models and features will not be compatible with Text Completions. See our [migration guide](https://platform.claude.com/docs/en/build-with-claude/working-with-messages) for guidance in migrating from Text Completions to Messages.

## Headers

- `anthropic-version` string — The version of the Claude API you want to use. Read more about versioning and our version history [here](https://platform.claude.com/docs/en/api/versioning).
- `anthropic-beta` string — Optional header to specify the beta version(s) you want to use. To use multiple betas, use a comma separated list like `beta1,beta2` or specify the header multiple times for each beta.

## Request body

- CompletionRequest
  - `model` union, required — The model that will complete your prompt. See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.
    - string
    - 'claude-sonnet-5' — High-performance model for coding and agents
    - 'claude-fable-5' — Next generation of intelligence for the hardest knowledge work and coding problems
    - 'claude-mythos-5' — Most capable model for cybersecurity and biology research
    - 'claude-opus-5' — Powerful intelligence for long-running agents and coding
    - 'claude-opus-4-8' — Powerful intelligence for long-running agents and coding
    - 'claude-opus-4-7' — Powerful intelligence for long-running agents and coding
    - 'claude-mythos-preview' — New class of intelligence, strongest in coding and cybersecurity
    - 'claude-opus-4-6' — Powerful intelligence for long-running agents and coding
    - 'claude-sonnet-4-6' — Best combination of speed and intelligence
    - 'claude-haiku-4-5' — Fastest model with near-frontier intelligence
    - 'claude-haiku-4-5-20251001' — Fastest model with near-frontier intelligence
    - 'claude-opus-4-5' — Powerful intelligence for long-running agents and coding
    - 'claude-opus-4-5-20251101' — Powerful intelligence for long-running agents and coding
    - 'claude-sonnet-4-5' — High-performance model for agents and coding
    - 'claude-sonnet-4-5-20250929' — High-performance model for agents and coding
  - `prompt` string, required — The prompt that you want Claude to complete. For proper response generation you will need to format your prompt using alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example: ``` "\n\nHuman: {userQuestion}\n\nAssistant:" ``` See [prompt validation](https://platform.claude.com/docs/en/build-with-claude/working-with-messages) and our guide to [prompt design](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/overview) for more details.
  - `max_tokens_to_sample` integer, required — The maximum number of tokens to generate before stopping. Note that our models may stop _before_ reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.
  - `stop_sequences` string[] — Sequences that will cause the model to stop generating. Our models stop on `"\n\nHuman:"`, and may include additional built-in stop sequences in the future. By providing the stop_sequences parameter, you may include additional strings that will cause the model to stop generating.
  - `temperature` number — Amount of randomness injected into the response. Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` for analytical / multiple choice, and closer to `1.0` for creative and generative tasks. Note that even with `temperature` of `0.0`, the results will not be fully deterministic.
  - `top_p` number — Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by `top_p`. Recommended for advanced use cases only.
  - `top_k` integer — Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). Recommended for advanced use cases only.
  - `metadata` Metadata
    - `user_id` string, nullable — An external identifier for the user who is associated with the request. This should be a uuid, hash value, or other opaque identifier. Anthropic may use this id to help detect abuse. Do not include any identifying information such as name, email address, or phone number.
  - `stream` boolean — Whether to incrementally stream the response using server-sent events. See [streaming](https://platform.claude.com/docs/en/build-with-claude/streaming) for details.

## Response `200`

Text Completion object.

- CompletionResponse
  - `completion` string, required — The resulting completion up to and excluding the stop sequences.
  - `id` string, required — Unique object identifier. The format and length of IDs may change over time.
  - `model` union, required — The model that will complete your prompt. See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.
    - string
    - 'claude-sonnet-5' — High-performance model for coding and agents
    - 'claude-fable-5' — Next generation of intelligence for the hardest knowledge work and coding problems
    - 'claude-mythos-5' — Most capable model for cybersecurity and biology research
    - 'claude-opus-5' — Powerful intelligence for long-running agents and coding
    - 'claude-opus-4-8' — Powerful intelligence for long-running agents and coding
    - 'claude-opus-4-7' — Powerful intelligence for long-running agents and coding
    - 'claude-mythos-preview' — New class of intelligence, strongest in coding and cybersecurity
    - 'claude-opus-4-6' — Powerful intelligence for long-running agents and coding
    - 'claude-sonnet-4-6' — Best combination of speed and intelligence
    - 'claude-haiku-4-5' — Fastest model with near-frontier intelligence
    - 'claude-haiku-4-5-20251001' — Fastest model with near-frontier intelligence
    - 'claude-opus-4-5' — Powerful intelligence for long-running agents and coding
    - 'claude-opus-4-5-20251101' — Powerful intelligence for long-running agents and coding
    - 'claude-sonnet-4-5' — High-performance model for agents and coding
    - 'claude-sonnet-4-5-20250929' — High-performance model for agents and coding
  - `stop_reason` string, nullable, required — The reason that we stopped. This may be one the following values: * `"stop_sequence"`: we reached a stop sequence — either provided by you via the `stop_sequences` parameter, or a stop sequence built into the model * `"max_tokens"`: we exceeded `max_tokens_to_sample` or the model's maximum
  - `type` 'completion', required — Object type. For Text Completions, this is always `"completion"`.

## Other responses

- `4XX` — Error response. See our [errors documentation](https://platform.claude.com/docs/en/api/errors) for more details.

---

[API](https://skmtc.net/anthropics/apis/anthropic-api.md) · [All operations](https://skmtc.net/anthropics/apis/anthropic-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/anthropics/anthropic-api/versions/93d8fd7d6493/schema)
