--- url: "https://platform.claude.com/docs/en/api/completions/create" titulek: "Create a Text Completion - Claude API Reference" h1: "Create a Text Completion" popis: "[Legacy] Create a Text Completion. The Text Completions API is a legacy API. We recommend using the Messages API going forward. Future models and features…" jazyk: "en" kanonicka: "https://platform.claude.com/docs/en/api/completions/create" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-15 02:24:59" znaku: 7100 slov: 937 kodovani: "iso-8859-2" sha256: "0d870cdd22e6582b64a4716b7bf19affc14313a469e3e57d56a49c18d3b0a18e" --- # 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-beta": optional array of [AnthropicBeta](/docs/en/api/http/beta#anthropic_beta)Optional header to specify the beta version(s) you want to use.One of the following:string"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 42 moreOne of the following:"message-batches-2024-09-24""prompt-caching-2024-07-31""computer-use-2024-10-22""computer-use-2025-01-24""pdfs-2024-09-25""token-counting-2024-11-01""token-efficient-tools-2025-02-19""output-128k-2025-02-19""files-api-2025-04-14""mcp-client-2025-04-04""mcp-client-2025-11-20""dev-full-thinking-2025-05-14""interleaved-thinking-2025-05-14""code-execution-2025-05-22""extended-cache-ttl-2025-04-11""context-1m-2025-08-07""context-management-2025-06-27""model-context-window-exceeded-2025-08-26""skills-2025-10-02""fast-mode-2026-02-01""output-300k-2026-03-24""user-profiles-2026-03-24""user-profiles-2026-08-18""user-profiles-2026-09-04""advisor-tool-2026-03-01""managed-agents-2026-04-01""cache-diagnosis-2026-04-07""dreaming-2026-04-21""thinking-token-count-2026-05-13""server-side-fallback-2026-06-01""server-side-fallback-2026-07-01""fallback-credit-2026-06-01""fallback-credit-2026-07-01""agent-memory-2026-07-22""mid-conversation-tool-changes-2026-07-01""compact-2026-01-12""computer-use-2025-11-24""mcp-tunnels-2026-06-22""structured-outputs-2025-11-13""task-budgets-2026-03-13""thinking-display-updates-2026-08-18""ce-user-management-2026-07-13""mid-conversation-output-config-2026-07-01""thinking-binding-controls-2026-08-01""mid-conversation-system-clear-at-2026-08-21" "anthropic-workspace-id": optional string ##### Body max_tokens_to_sample: numberThe 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.minimum1 model: [Model](/docs/en/api/http/messages#model)The model that will complete your prompt.See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.One of the following: prompt: stringThe prompt that you want Claude to complete.For proper response generation you will need to format your prompt using alternating ` Human:`and` Assistant:` conversational turns. For example: `" Human: {userQuestion} Assistant:"` 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.minLength1 metadata: optional [Metadata](/docs/en/api/http/messages#metadata) { user_id }An object describing metadata about the request.user_id: optional string or nullAn 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.maxLength512 stop_sequences: optional array of stringSequences that will cause the model to stop generating.Our models stop on `" 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. stream: optional booleanWhether to incrementally stream the response using server-sent events.See [streaming](https://platform.claude.com/docs/en/build-with-claude/streaming) for details. temperature: optional number⁠DeprecatedAmount of randomness injected into the response.Deprecated. Models released after Claude Opus 4.6 do not support setting temperature. A value of 1.0 of will be accepted for backwards compatibility, all other values will be rejected with a 400 error.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.maximum1minimum0 top_k: optional number⁠DeprecatedOnly sample from the top K options for each subsequent token.Deprecated. Models released after Claude Opus 4.6 do not accept top_k; any value will be rejected with a 400 error.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.minimum0 top_p: optional number⁠DeprecatedUse nucleus sampling.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.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.maximum1minimum0 ##### Returns Completion object{ type, id, completion, 2 more }type: "completion"Object type.For Text Completions, this is always `"completion"`.defaultcompletionid: stringUnique object identifier.The format and length of IDs may change over time.completion: stringThe resulting completion up to and excluding the stop sequences.model: [Model](/docs/en/api/http/messages#model)The model that will complete your prompt.See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.One of the following:stop_reason: string or nullThe 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  Create a Text Completion ``` curl https://api.anthropic.com/v1/complete \ -H 'Content-Type: application/json' \ -H 'anthropic-version: 2023-06-01' \ -H "X-Api-Key: $ANTHROPIC_API_KEY" \ --max-time 600 \ -d '{ "max_tokens_to_sample": 256, "model": "claude-2.1", "prompt": "\n\nHuman: Hello, world!\n\nAssistant:", "temperature": 1, "top_k": 5, "top_p": 0.7 }' ``` Response 200 ``` { "id": "compl_018CKm6gsux7P8yMcwZbeCPw", "completion": " Hello! My name is Claude.", "model": "claude-2.1", "stop_reason": "stop_sequence", "type": "completion" } ``` ##### Returns Examples Response 200 ``` { "id": "compl_018CKm6gsux7P8yMcwZbeCPw", "completion": " Hello! My name is Claude.", "model": "claude-2.1", "stop_reason": "stop_sequence", "type": "completion" } ```