Create a Text Completion
[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 will not be compatible with Text Completions. See our migration guide for guidance in migrating from Text Completions to Messages.
Headers
The version of the Anthropic API you want to use.
Read more about versioning and our version history here.
Your unique API key for authentication.
This key is required in the header of all API requests, to authenticate your account and access Anthropic's services. Get your API key through the Console. Each key is scoped to a Workspace.
Body
The model that will complete your prompt.
See models for additional details and options.
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 and our guide to prompt design for more details.
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.
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.
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.
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
. You should either alter temperature
or top_p
, but not both.
Recommended for advanced use cases only. You usually only need to use temperature
.
Only sample from the top K options for each subsequent token.
Used to remove "long tail" low probability responses. Learn more technical details here.
Recommended for advanced use cases only. You usually only need to use temperature
.
An object describing metadata about the request.
Whether to incrementally stream the response using server-sent events.
See streaming for details.
Response
Object type.
For Text Completions, this is always "completion"
.
completion
Unique object identifier.
The format and length of IDs may change over time.
The resulting completion up to and excluding the stop sequences.
The reason that we stopped.
This may be one the following values:
"stop_sequence"
: we reached a stop sequence — either provided by you via thestop_sequences
parameter, or a stop sequence built into the model"max_tokens"
: we exceededmax_tokens_to_sample
or the model's maximum
The model that handled the request.
Was this page helpful?