---
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.
- `anthropic-workspace-id` string

## 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-fable-5-1' — Frontier intelligence for ambitious tasks across coding, scientific discovery, and enterprise workflows
    - 'claude-mythos-5-1' — Our most capable model for cybersecurity and biology research, available through trusted access programs
    - '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-fable-5-1' — Frontier intelligence for ambitious tasks across coding, scientific discovery, and enterprise workflows
    - 'claude-mythos-5-1' — Our most capable model for cybersecurity and biology research, available through trusted access programs
    - '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

- `400` — Invalid argument - The client specified an invalid argument
- `401` — Unauthenticated - The request does not have valid authentication credentials
- `403` — Permission denied - The caller does not have permission to execute the specified operation
- `404` — Not found - Some requested entity was not found
- `408` — Deadline exceeded - The deadline expired before the operation could complete
- `409` — Aborted - The operation was aborted due to concurrency issue
- `412` — Failed precondition - Operation was rejected because the system is not in required state
- `413` — Out of range - Operation was attempted past the valid range
- `429` — Resource exhausted - Some resource has been exhausted (rate limiting)
- `431` — Request header fields too large - Request metadata was too large
- `499` — Cancelled - The operation was cancelled by the client
- `500` — Internal - Internal server error
- `501` — Unimplemented - The operation is not implemented or supported
- `503` — Unavailable - The service is currently unavailable
- `504` — Deadline exceeded - Upstream service did not respond in time
- `529` — Overloaded - The service is temporarily overloaded

## Changes

- **2026-09-02** `4789294140a2` — 17 info
  - added the new optional `header` request parameter `anthropic-workspace-id`
  - added the non-success response with the status `400`
  - added the non-success response with the status `401`
  - added the non-success response with the status `403`
  - …13 more
- **2026-09-01** `d1d189d791d1` — 2 info
  - added `subschema #2, subschema #3` to the `model` request property `anyOf` list
  - added `subschema #2, subschema #3` to the `model` response property `anyOf` list for the response status `200`
- **2026-08-06** `538e9bd0db77` — 1 breaking, 1 info
  - removed `subschema #17, subschema #18` from the `model` request property `anyOf` list
  - removed `subschema #17, subschema #18` 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.dev/anthropics/apis/anthropic-api/revisions/1bb7c7a0a4a9?raw)
