---
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://docs.claude.com/en/api/messages) going forward.

Future models and features will not be compatible with Text Completions. See our [migration guide](https://docs.claude.com/en/api/migrating-from-text-completions-to-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://docs.claude.com/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.\n\nSee [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.
    - string
    - 'claude-opus-4-6' — Most intelligent model for building 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' — Premium model combining maximum intelligence with practical performance
    - 'claude-opus-4-5-20251101' — Premium model combining maximum intelligence with practical performance
    - 'claude-sonnet-4-5' — High-performance model for agents and coding
    - 'claude-sonnet-4-5-20250929' — High-performance model for agents and coding
    - 'claude-opus-4-1' — Exceptional model for specialized complex tasks
    - 'claude-opus-4-1-20250805' — Exceptional model for specialized complex tasks
    - 'claude-opus-4-0' — Powerful model for complex tasks
    - 'claude-opus-4-20250514' — Powerful model for complex tasks
    - 'claude-sonnet-4-0' — High-performance model with extended thinking
    - 'claude-sonnet-4-20250514' — High-performance model with extended thinking
    - 'claude-3-haiku-20240307' — Fast and cost-effective model
  - `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://docs.claude.com/en/api/prompt-validation) and our guide to [prompt design](https://docs.claude.com/en/docs/intro-to-prompting) 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`. You should either alter `temperature` or `top_p`, but not both. Recommended for advanced use cases only. You usually only need to use `temperature`.
  - `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. You usually only need to use `temperature`.
  - `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://docs.claude.com/en/api/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.\n\nSee [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.
    - string
    - 'claude-opus-4-6' — Most intelligent model for building 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' — Premium model combining maximum intelligence with practical performance
    - 'claude-opus-4-5-20251101' — Premium model combining maximum intelligence with practical performance
    - 'claude-sonnet-4-5' — High-performance model for agents and coding
    - 'claude-sonnet-4-5-20250929' — High-performance model for agents and coding
    - 'claude-opus-4-1' — Exceptional model for specialized complex tasks
    - 'claude-opus-4-1-20250805' — Exceptional model for specialized complex tasks
    - 'claude-opus-4-0' — Powerful model for complex tasks
    - 'claude-opus-4-20250514' — Powerful model for complex tasks
    - 'claude-sonnet-4-0' — High-performance model with extended thinking
    - 'claude-sonnet-4-20250514' — High-performance model with extended thinking
    - 'claude-3-haiku-20240307' — Fast and cost-effective model
  - `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://docs.claude.com/en/api/errors) for more details.

## Changes

- **2026-03-18** `dd2dcd00a757` — 1 info
  - the `metadata/user_id/anyOf[subschema #1]/` request property's maxLength was increased from `256` to `512`
- **2026-03-16** `7fce94a3c9f7` — 1 breaking, 3 info
  - removed `subschema #3, subschema #6, subschema #7, subschema #8, subschema #9, subschema #10, subschema #11, subschema #14, subschema #15, subschema #16, subschema #17, subschema #18, subschema #19, subschema #20, subschema #21, subschema #22, subschema #23` from the `model` request property `anyOf` list
  - added `subschema #3, subschema #4, subschema #5, subschema #8, subschema #9, subschema #10, subschema #11, subschema #12, subschema #13, subschema #16` to the `model` request property `anyOf` list
  - added `subschema #3, subschema #4, subschema #5, subschema #8, subschema #9, subschema #10, subschema #11, subschema #12, subschema #13, subschema #16` to the `model` response property `anyOf` list for the response status `200`
  - removed `subschema #3, subschema #6, subschema #7, subschema #8, subschema #9, subschema #10, subschema #11, subschema #14, subschema #15, subschema #16, subschema #17, subschema #18, subschema #19, subschema #20, subschema #21, subschema #22, subschema #23` from the `model` response property `anyOf` list for the response status `200`
- …earlier changes not shown

[Full history](https://skmtc.dev/anthropics/apis/anthropic-api/changes/v1/complete/post.md)

---

[API](https://skmtc.dev/anthropics/apis/anthropic-api.md) · [All operations](https://skmtc.dev/anthropics/apis/anthropic-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/anthropics/anthropic-api/revisions/dd2dcd00a757/schema)
