POST
POST /v1/complete — Claude API
Beta
Anthropic API key (required); https://api.anthropic.com
Claude APICreate a Text Completion
- Base URL
- https://api.anthropic.com
- Auth
- x-api-key: <ANTHROPIC_API_KEY>
- Last verified
- 2026-10-20 · upstream hash matched
Actions Try in browser→
Agents: curl -H "Accept: text/markdown" this URL
→ 398 tokens · Vary: Accept
→ 398 tokens · Vary: Accept
Critical gotchas
Authentication uses the x-api-key header and requests also require an anthropic-version header.
The official OpenAPI URL is discovered from the SDK repository manifest and must remain under Anthropic's trusted Stainless storage prefix.
cURL
curl -X POST 'https://api.anthropic.com/v1/complete' \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H 'anthropic-version: 2023-06-01' \ -H 'Content-Type: application/json' \ -d '{ "model": "example-model", "prompt": "example-prompt", "max_tokens_to_sample": 0}'
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| model | body | string | Yes | The model that will complete your prompt. See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options. |
| prompt | body | string | Yes | 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 | body | integer | Yes | 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 | body | string[] | No | 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 | body | number | No | 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 | body | number | No | 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 | body | integer | No | 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 | body | object | No | Request body field metadata. |
| stream | body | boolean | No | 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 OK
{
"completion": " Hello! My name is Claude.",
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
} Get a free Claude API key → sponsored Affiliate link - we may earn a commission, at no extra cost to you.