SPB Git

Repository Public

completions.md 14.1 KB 555 lines markdown

1---2title: Completions3url: https://platform.claude.com/docs/en/api/completions4---56# Completions78## Create a Text Completion910**POST** `/v1/complete`1112[Legacy] Create a Text Completion.1314The Text Completions API is a legacy API. We recommend using the [Messages API](https://platform.claude.com/docs/en/api/messages) going forward.1516Future 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.1718### Headers1920- `"anthropic-beta": optional array of AnthropicBeta`2122  Optional header to specify the beta version(s) you want to use.2324  - `string`2526  - `"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 43 more`2728    - `"message-batches-2024-09-24"`2930    - `"prompt-caching-2024-07-31"`3132    - `"computer-use-2024-10-22"`3334    - `"computer-use-2025-01-24"`3536    - `"pdfs-2024-09-25"`3738    - `"token-counting-2024-11-01"`3940    - `"token-efficient-tools-2025-02-19"`4142    - `"output-128k-2025-02-19"`4344    - `"files-api-2025-04-14"`4546    - `"mcp-client-2025-04-04"`4748    - `"mcp-client-2025-11-20"`4950    - `"dev-full-thinking-2025-05-14"`5152    - `"interleaved-thinking-2025-05-14"`5354    - `"code-execution-2025-05-22"`5556    - `"extended-cache-ttl-2025-04-11"`5758    - `"context-1m-2025-08-07"`5960    - `"context-management-2025-06-27"`6162    - `"model-context-window-exceeded-2025-08-26"`6364    - `"skills-2025-10-02"`6566    - `"fast-mode-2026-02-01"`6768    - `"output-300k-2026-03-24"`6970    - `"user-profiles-2026-03-24"`7172    - `"user-profiles-2026-08-18"`7374    - `"user-profiles-2026-09-04"`7576    - `"advisor-tool-2026-03-01"`7778    - `"managed-agents-2026-04-01"`7980    - `"cache-diagnosis-2026-04-07"`8182    - `"dreaming-2026-04-21"`8384    - `"thinking-token-count-2026-05-13"`8586    - `"server-side-fallback-2026-06-01"`8788    - `"server-side-fallback-2026-07-01"`8990    - `"fallback-credit-2026-06-01"`9192    - `"fallback-credit-2026-07-01"`9394    - `"agent-memory-2026-07-22"`9596    - `"mid-conversation-tool-changes-2026-07-01"`9798    - `"compact-2026-01-12"`99100    - `"computer-use-2025-11-24"`101102    - `"mcp-tunnels-2026-06-22"`103104    - `"structured-outputs-2025-11-13"`105106    - `"task-budgets-2026-03-13"`107108    - `"thinking-display-updates-2026-08-18"`109110    - `"ce-user-management-2026-07-13"`111112    - `"mid-conversation-output-config-2026-07-01"`113114    - `"thinking-binding-controls-2026-08-01"`115116    - `"mid-conversation-system-clear-at-2026-08-21"`117118    - `"compact-2026-09-04"`119120- `"anthropic-workspace-id": optional string`121122### Body parameters123124- `max_tokens_to_sample: number`125126  The maximum number of tokens to generate before stopping.127128  Note that our models may stop _before_ reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.129130  minimum: 1131132- `model: Model`133134  The model that will complete your prompt.135136  See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.137138  - `"claude-fable-5-1" or "claude-mythos-5-1" or "claude-sonnet-5" or 14 more`139140    The model that will complete your prompt.141142    See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.143144    - `"claude-fable-5-1"`145146      Frontier intelligence for ambitious tasks across coding, scientific discovery, and enterprise workflows147148    - `"claude-mythos-5-1"`149150      Our most capable model for cybersecurity and biology research, available through trusted access programs151152    - `"claude-sonnet-5"`153154      High-performance model for coding and agents155156    - `"claude-fable-5"`157158      Next generation of intelligence for the hardest knowledge work and coding problems159160    - `"claude-mythos-5"`161162      Most capable model for cybersecurity and biology research163164    - `"claude-opus-5"`165166      Powerful intelligence for long-running agents and coding167168    - `"claude-opus-4-8"`169170      Powerful intelligence for long-running agents and coding171172    - `"claude-opus-4-7"`173174      Powerful intelligence for long-running agents and coding175176    - `"claude-mythos-preview"`177178      New class of intelligence, strongest in coding and cybersecurity179180    - `"claude-opus-4-6"`181182      Powerful intelligence for long-running agents and coding183184    - `"claude-sonnet-4-6"`185186      Best combination of speed and intelligence187188    - `"claude-haiku-4-5"`189190      Fastest model with near-frontier intelligence191192    - `"claude-haiku-4-5-20251001"`193194      Fastest model with near-frontier intelligence195196    - `"claude-opus-4-5"`197198      Powerful intelligence for long-running agents and coding199200    - `"claude-opus-4-5-20251101"`201202      Powerful intelligence for long-running agents and coding203204    - `"claude-sonnet-4-5"`205206      High-performance model for agents and coding207208    - `"claude-sonnet-4-5-20250929"`209210      High-performance model for agents and coding211212  - `string`213214- `prompt: string`215216  The prompt that you want Claude to complete.217218  For proper response generation you will need to format your prompt using alternating `219220  Human:`and`221222  Assistant:` conversational turns. For example:223224  ```225  "226  227  Human: {userQuestion}228  229  Assistant:"230  ```231232  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.233234  minLength: 1235236- `metadata: optional Metadata`237238  An object describing metadata about the request.239240  - `user_id: optional string or null`241242    An external identifier for the user who is associated with the request.243244    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.245246    maxLength: 512247248- `stop_sequences: optional array of string`249250  Sequences that will cause the model to stop generating.251252  Our models stop on `"253254  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.255256- `stream: optional boolean`257258  Whether to incrementally stream the response using server-sent events.259260  See [streaming](https://platform.claude.com/docs/en/build-with-claude/streaming) for details.261262- `temperature: optional number`263264  **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.265266  Amount of randomness injected into the response.267268  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.269270  Note that even with `temperature` of `0.0`, the results will not be fully deterministic.271272  maximum: 1, minimum: 0273274- `top_k: optional number`275276  **Deprecated**: Deprecated. Models released after Claude Opus 4.6 do not accept top_k; any value will be rejected with a 400 error.277278  Only sample from the top K options for each subsequent token.279280  Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).281282  Recommended for advanced use cases only.283284  minimum: 0285286- `top_p: optional number`287288  **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.289290  Use nucleus sampling.291292  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`.293294  Recommended for advanced use cases only.295296  maximum: 1, minimum: 0297298### Returns299300- `Completion object`301302  - `type: "completion"`303304    Object type.305306    For Text Completions, this is always `"completion"`.307308    default: completion309310  - `id: string`311312    Unique object identifier.313314    The format and length of IDs may change over time.315316  - `completion: string`317318    The resulting completion up to and excluding the stop sequences.319320  - `model: Model`321322    The model that will complete your prompt.323324    See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.325326    - `"claude-fable-5-1" or "claude-mythos-5-1" or "claude-sonnet-5" or 14 more`327328      The model that will complete your prompt.329330      See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.331332      - `"claude-fable-5-1"`333334        Frontier intelligence for ambitious tasks across coding, scientific discovery, and enterprise workflows335336      - `"claude-mythos-5-1"`337338        Our most capable model for cybersecurity and biology research, available through trusted access programs339340      - `"claude-sonnet-5"`341342        High-performance model for coding and agents343344      - `"claude-fable-5"`345346        Next generation of intelligence for the hardest knowledge work and coding problems347348      - `"claude-mythos-5"`349350        Most capable model for cybersecurity and biology research351352      - `"claude-opus-5"`353354        Powerful intelligence for long-running agents and coding355356      - `"claude-opus-4-8"`357358        Powerful intelligence for long-running agents and coding359360      - `"claude-opus-4-7"`361362        Powerful intelligence for long-running agents and coding363364      - `"claude-mythos-preview"`365366        New class of intelligence, strongest in coding and cybersecurity367368      - `"claude-opus-4-6"`369370        Powerful intelligence for long-running agents and coding371372      - `"claude-sonnet-4-6"`373374        Best combination of speed and intelligence375376      - `"claude-haiku-4-5"`377378        Fastest model with near-frontier intelligence379380      - `"claude-haiku-4-5-20251001"`381382        Fastest model with near-frontier intelligence383384      - `"claude-opus-4-5"`385386        Powerful intelligence for long-running agents and coding387388      - `"claude-opus-4-5-20251101"`389390        Powerful intelligence for long-running agents and coding391392      - `"claude-sonnet-4-5"`393394        High-performance model for agents and coding395396      - `"claude-sonnet-4-5-20250929"`397398        High-performance model for agents and coding399400    - `string`401402  - `stop_reason: string or null`403404    The reason that we stopped.405406    This may be one the following values:407408    * `"stop_sequence"`: we reached a stop sequence — either provided by you via the `stop_sequences` parameter, or a stop sequence built into the model409    * `"max_tokens"`: we exceeded `max_tokens_to_sample` or the model's maximum410411### Example412413```bash414curl https://api.anthropic.com/v1/complete \415    -H 'Content-Type: application/json' \416    -H 'anthropic-version: 2023-06-01' \417    -H "X-Api-Key: $ANTHROPIC_API_KEY" \418    --max-time 600 \419    -d '{420          "max_tokens_to_sample": 256,421          "model": "claude-2.1",422          "prompt": "\n\nHuman: Hello, world!\n\nAssistant:",423          "temperature": 1,424          "top_k": 5,425          "top_p": 0.7426        }'427```428429#### Response (200)430431```json432{433  "id": "compl_018CKm6gsux7P8yMcwZbeCPw",434  "completion": " Hello! My name is Claude.",435  "model": "claude-2.1",436  "stop_reason": "stop_sequence",437  "type": "completion"438}439```440441## Domain types442443### Completion444445- `Completion object`446447  - `type: "completion"`448449    Object type.450451    For Text Completions, this is always `"completion"`.452453    default: completion454455  - `id: string`456457    Unique object identifier.458459    The format and length of IDs may change over time.460461  - `completion: string`462463    The resulting completion up to and excluding the stop sequences.464465  - `model: Model`466467    The model that will complete your prompt.468469    See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.470471    - `"claude-fable-5-1" or "claude-mythos-5-1" or "claude-sonnet-5" or 14 more`472473      The model that will complete your prompt.474475      See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.476477      - `"claude-fable-5-1"`478479        Frontier intelligence for ambitious tasks across coding, scientific discovery, and enterprise workflows480481      - `"claude-mythos-5-1"`482483        Our most capable model for cybersecurity and biology research, available through trusted access programs484485      - `"claude-sonnet-5"`486487        High-performance model for coding and agents488489      - `"claude-fable-5"`490491        Next generation of intelligence for the hardest knowledge work and coding problems492493      - `"claude-mythos-5"`494495        Most capable model for cybersecurity and biology research496497      - `"claude-opus-5"`498499        Powerful intelligence for long-running agents and coding500501      - `"claude-opus-4-8"`502503        Powerful intelligence for long-running agents and coding504505      - `"claude-opus-4-7"`506507        Powerful intelligence for long-running agents and coding508509      - `"claude-mythos-preview"`510511        New class of intelligence, strongest in coding and cybersecurity512513      - `"claude-opus-4-6"`514515        Powerful intelligence for long-running agents and coding516517      - `"claude-sonnet-4-6"`518519        Best combination of speed and intelligence520521      - `"claude-haiku-4-5"`522523        Fastest model with near-frontier intelligence524525      - `"claude-haiku-4-5-20251001"`526527        Fastest model with near-frontier intelligence528529      - `"claude-opus-4-5"`530531        Powerful intelligence for long-running agents and coding532533      - `"claude-opus-4-5-20251101"`534535        Powerful intelligence for long-running agents and coding536537      - `"claude-sonnet-4-5"`538539        High-performance model for agents and coding540541      - `"claude-sonnet-4-5-20250929"`542543        High-performance model for agents and coding544545    - `string`546547  - `stop_reason: string or null`548549    The reason that we stopped.550551    This may be one the following values:552553    * `"stop_sequence"`: we reached a stop sequence — either provided by you via the `stop_sequences` parameter, or a stop sequence built into the model554    * `"max_tokens"`: we exceeded `max_tokens_to_sample` or the model's maximum555
Files main
Menu

Theme