建立文字補全
[舊版] 建立文字補全。
Text Completions API 是舊版 API。我們建議日後改用 Messages API。
未來的模型與功能將不相容於 Text Completions。請參閱我們的遷移指南,以瞭解從 Text Completions 遷移至 Messages 的指引。
Parameters
--max-tokens-to-sample: numberBody param: The maximum number of tokens to generate before stopping.
Body param: 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.
--model: "claude-fable-5-1" or "claude-mythos-5-1" or "claude-sonnet-5" or 14 more or stringBody param: The model that will complete your prompt.
Body param: The model that will complete your prompt.
See models for additional details and options.
--prompt: stringBody param: The prompt that you want Claude to complete.
Body param: The 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 and our guide to prompt design for more details.
Body param: An object describing metadata about the request.
--stop-sequence: optional array of stringBody param: Sequences that will cause the model to stop generating.
Body param: Sequences 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.
Header param: Optional header to specify the beta version(s) you want to use.
--temperature: optional numberDeprecatedBody param: Amount of randomness injected into the response.
Body param: 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-k: optional numberDeprecatedBody param: Only sample from the top K options for each subsequent token.
Body param: 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.
--top-p: optional numberDeprecatedBody param: Use nucleus sampling.
Body param: 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.
Returns
completion: object{ id, completion, model, 2 more }
id: stringUnique object identifier.
Unique object identifier.
The format and length of IDs may change over time.
The resulting completion up to and excluding the stop sequences.
model: "claude-fable-5-1" or "claude-mythos-5-1" or "claude-sonnet-5" or 14 more or stringThe model that will complete your prompt.
The model that will complete your prompt.
See models for additional details and options.
Frontier intelligence for ambitious tasks across coding, scientific discovery, and enterprise workflows
Our most capable model for cybersecurity and biology research, available through trusted access programs
High-performance model for coding and agents
Next generation of intelligence for the hardest knowledge work and coding problems
Most capable model for cybersecurity and biology research
Powerful intelligence for long-running agents and coding
Powerful intelligence for long-running agents and coding
Powerful intelligence for long-running agents and coding
New class of intelligence, strongest in coding and cybersecurity
Powerful intelligence for long-running agents and coding
Best combination of speed and intelligence
Fastest model with near-frontier intelligence
Fastest model with near-frontier intelligence
Powerful intelligence for long-running agents and coding
Powerful intelligence for long-running agents and coding
High-performance model for agents and coding
High-performance model for agents and coding
stop_reason: stringThe reason that we stopped.
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_sequencesparameter, or a stop sequence built into the model"max_tokens": we exceededmax_tokens_to_sampleor the model's maximum
type: "completion"Object type.
Object type.
For Text Completions, this is always "completion".
completion: object{ id, completion, model, 2 more }
ant completions create \
--api-key my-anthropic-api-key \
--max-tokens-to-sample 256 \
--model claude-fable-5-1 \
--prompt '
Human: Hello, world!
Assistant:'{
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"completion": " Hello! My name is Claude.",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
}Returns Examples
{
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"completion": " Hello! My name is Claude.",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
}