Repository Public
1---2title: Create a Text Completion3url: https://platform.claude.com/docs/en/api/completions/create4---56# Create a Text Completion78**POST** `/v1/complete`910[Legacy] Create a Text Completion.1112The Text Completions API is a legacy API. We recommend using the [Messages API](https://platform.claude.com/docs/en/api/messages) going forward.1314Future 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.1516## Headers1718- `"anthropic-beta": optional array of AnthropicBeta`1920 Optional header to specify the beta version(s) you want to use.2122 - `string`2324 - `"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 43 more`2526 - `"message-batches-2024-09-24"`2728 - `"prompt-caching-2024-07-31"`2930 - `"computer-use-2024-10-22"`3132 - `"computer-use-2025-01-24"`3334 - `"pdfs-2024-09-25"`3536 - `"token-counting-2024-11-01"`3738 - `"token-efficient-tools-2025-02-19"`3940 - `"output-128k-2025-02-19"`4142 - `"files-api-2025-04-14"`4344 - `"mcp-client-2025-04-04"`4546 - `"mcp-client-2025-11-20"`4748 - `"dev-full-thinking-2025-05-14"`4950 - `"interleaved-thinking-2025-05-14"`5152 - `"code-execution-2025-05-22"`5354 - `"extended-cache-ttl-2025-04-11"`5556 - `"context-1m-2025-08-07"`5758 - `"context-management-2025-06-27"`5960 - `"model-context-window-exceeded-2025-08-26"`6162 - `"skills-2025-10-02"`6364 - `"fast-mode-2026-02-01"`6566 - `"output-300k-2026-03-24"`6768 - `"user-profiles-2026-03-24"`6970 - `"user-profiles-2026-08-18"`7172 - `"user-profiles-2026-09-04"`7374 - `"advisor-tool-2026-03-01"`7576 - `"managed-agents-2026-04-01"`7778 - `"cache-diagnosis-2026-04-07"`7980 - `"dreaming-2026-04-21"`8182 - `"thinking-token-count-2026-05-13"`8384 - `"server-side-fallback-2026-06-01"`8586 - `"server-side-fallback-2026-07-01"`8788 - `"fallback-credit-2026-06-01"`8990 - `"fallback-credit-2026-07-01"`9192 - `"agent-memory-2026-07-22"`9394 - `"mid-conversation-tool-changes-2026-07-01"`9596 - `"compact-2026-01-12"`9798 - `"computer-use-2025-11-24"`99100 - `"mcp-tunnels-2026-06-22"`101102 - `"structured-outputs-2025-11-13"`103104 - `"task-budgets-2026-03-13"`105106 - `"thinking-display-updates-2026-08-18"`107108 - `"ce-user-management-2026-07-13"`109110 - `"mid-conversation-output-config-2026-07-01"`111112 - `"thinking-binding-controls-2026-08-01"`113114 - `"mid-conversation-system-clear-at-2026-08-21"`115116 - `"compact-2026-09-04"`117118- `"anthropic-workspace-id": optional string`119120## Body parameters121122- `max_tokens_to_sample: number`123124 The maximum number of tokens to generate before stopping.125126 Note that our models may stop _before_ reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.127128 minimum: 1129130- `model: Model`131132 The model that will complete your prompt.133134 See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.135136 - `"claude-fable-5-1" or "claude-mythos-5-1" or "claude-sonnet-5" or 14 more`137138 The model that will complete your prompt.139140 See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.141142 - `"claude-fable-5-1"`143144 Frontier intelligence for ambitious tasks across coding, scientific discovery, and enterprise workflows145146 - `"claude-mythos-5-1"`147148 Our most capable model for cybersecurity and biology research, available through trusted access programs149150 - `"claude-sonnet-5"`151152 High-performance model for coding and agents153154 - `"claude-fable-5"`155156 Next generation of intelligence for the hardest knowledge work and coding problems157158 - `"claude-mythos-5"`159160 Most capable model for cybersecurity and biology research161162 - `"claude-opus-5"`163164 Powerful intelligence for long-running agents and coding165166 - `"claude-opus-4-8"`167168 Powerful intelligence for long-running agents and coding169170 - `"claude-opus-4-7"`171172 Powerful intelligence for long-running agents and coding173174 - `"claude-mythos-preview"`175176 New class of intelligence, strongest in coding and cybersecurity177178 - `"claude-opus-4-6"`179180 Powerful intelligence for long-running agents and coding181182 - `"claude-sonnet-4-6"`183184 Best combination of speed and intelligence185186 - `"claude-haiku-4-5"`187188 Fastest model with near-frontier intelligence189190 - `"claude-haiku-4-5-20251001"`191192 Fastest model with near-frontier intelligence193194 - `"claude-opus-4-5"`195196 Powerful intelligence for long-running agents and coding197198 - `"claude-opus-4-5-20251101"`199200 Powerful intelligence for long-running agents and coding201202 - `"claude-sonnet-4-5"`203204 High-performance model for agents and coding205206 - `"claude-sonnet-4-5-20250929"`207208 High-performance model for agents and coding209210 - `string`211212- `prompt: string`213214 The prompt that you want Claude to complete.215216 For proper response generation you will need to format your prompt using alternating `217218 Human:`and`219220 Assistant:` conversational turns. For example:221222 ```223 "224 225 Human: {userQuestion}226 227 Assistant:"228 ```229230 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.231232 minLength: 1233234- `metadata: optional Metadata`235236 An object describing metadata about the request.237238 - `user_id: optional string or null`239240 An external identifier for the user who is associated with the request.241242 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.243244 maxLength: 512245246- `stop_sequences: optional array of string`247248 Sequences that will cause the model to stop generating.249250 Our models stop on `"251252 Human:"`, 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.253254- `stream: optional boolean`255256 Whether to incrementally stream the response using server-sent events.257258 See [streaming](https://platform.claude.com/docs/en/build-with-claude/streaming) for details.259260- `temperature: optional number`261262 **Deprecated**: Deprecated. Models released after Claude Opus 4.6 do not support setting temperature. A value of 1.0 will be accepted for backwards compatibility, all other values will be rejected with a 400 error.263264 Amount of randomness injected into the response.265266 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.267268 Note that even with `temperature` of `0.0`, the results will not be fully deterministic.269270 maximum: 1, minimum: 0271272- `top_k: optional number`273274 **Deprecated**: Deprecated. Models released after Claude Opus 4.6 do not accept top_k; any value will be rejected with a 400 error.275276 Only sample from the top K options for each subsequent token.277278 Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).279280 Recommended for advanced use cases only.281282 minimum: 0283284- `top_p: optional number`285286 **Deprecated**: Deprecated. Models released after Claude Opus 4.6 do not support setting top_p. A value >= 0.99 will be accepted for backwards compatibility, all other values will be rejected with a 400 error.287288 Use nucleus sampling.289290 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`.291292 Recommended for advanced use cases only.293294 maximum: 1, minimum: 0295296## Returns297298- `Completion object`299300 - `type: "completion"`301302 Object type.303304 For Text Completions, this is always `"completion"`.305306 default: completion307308 - `id: string`309310 Unique object identifier.311312 The format and length of IDs may change over time.313314 - `completion: string`315316 The resulting completion up to and excluding the stop sequences.317318 - `model: Model`319320 The model that will complete your prompt.321322 See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.323324 - `"claude-fable-5-1" or "claude-mythos-5-1" or "claude-sonnet-5" or 14 more`325326 The model that will complete your prompt.327328 See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.329330 - `"claude-fable-5-1"`331332 Frontier intelligence for ambitious tasks across coding, scientific discovery, and enterprise workflows333334 - `"claude-mythos-5-1"`335336 Our most capable model for cybersecurity and biology research, available through trusted access programs337338 - `"claude-sonnet-5"`339340 High-performance model for coding and agents341342 - `"claude-fable-5"`343344 Next generation of intelligence for the hardest knowledge work and coding problems345346 - `"claude-mythos-5"`347348 Most capable model for cybersecurity and biology research349350 - `"claude-opus-5"`351352 Powerful intelligence for long-running agents and coding353354 - `"claude-opus-4-8"`355356 Powerful intelligence for long-running agents and coding357358 - `"claude-opus-4-7"`359360 Powerful intelligence for long-running agents and coding361362 - `"claude-mythos-preview"`363364 New class of intelligence, strongest in coding and cybersecurity365366 - `"claude-opus-4-6"`367368 Powerful intelligence for long-running agents and coding369370 - `"claude-sonnet-4-6"`371372 Best combination of speed and intelligence373374 - `"claude-haiku-4-5"`375376 Fastest model with near-frontier intelligence377378 - `"claude-haiku-4-5-20251001"`379380 Fastest model with near-frontier intelligence381382 - `"claude-opus-4-5"`383384 Powerful intelligence for long-running agents and coding385386 - `"claude-opus-4-5-20251101"`387388 Powerful intelligence for long-running agents and coding389390 - `"claude-sonnet-4-5"`391392 High-performance model for agents and coding393394 - `"claude-sonnet-4-5-20250929"`395396 High-performance model for agents and coding397398 - `string`399400 - `stop_reason: string or null`401402 The reason that we stopped.403404 This may be one the following values:405406 * `"stop_sequence"`: we reached a stop sequence — either provided by you via the `stop_sequences` parameter, or a stop sequence built into the model407 * `"max_tokens"`: we exceeded `max_tokens_to_sample` or the model's maximum408409## Example410411```bash412curl https://api.anthropic.com/v1/complete \413 -H 'Content-Type: application/json' \414 -H 'anthropic-version: 2023-06-01' \415 -H "X-Api-Key: $ANTHROPIC_API_KEY" \416 --max-time 600 \417 -d '{418 "max_tokens_to_sample": 256,419 "model": "claude-2.1",420 "prompt": "\n\nHuman: Hello, world!\n\nAssistant:",421 "temperature": 1,422 "top_k": 5,423 "top_p": 0.7424 }'425```426427### Response (200)428429```json430{431 "id": "compl_018CKm6gsux7P8yMcwZbeCPw",432 "completion": " Hello! My name is Claude.",433 "model": "claude-2.1",434 "stop_reason": "stop_sequence",435 "type": "completion"436}437```438