create() — anthropic-sdk-python Function Reference
Architecture documentation for the create() function in completions.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 1ad0872e_46dc_091c_0877_a50b5dcb058e["create()"] 3f9319c4_6f30_5159_c278_2ec1abd634e9["Completions"] 1ad0872e_46dc_091c_0877_a50b5dcb058e -->|defined in| 3f9319c4_6f30_5159_c278_2ec1abd634e9 9c317a4f_95bc_c2b1_0575_0c4abd5aa170["create()"] 9c317a4f_95bc_c2b1_0575_0c4abd5aa170 -->|calls| 1ad0872e_46dc_091c_0877_a50b5dcb058e 9c317a4f_95bc_c2b1_0575_0c4abd5aa170["create()"] 1ad0872e_46dc_091c_0877_a50b5dcb058e -->|calls| 9c317a4f_95bc_c2b1_0575_0c4abd5aa170 style 1ad0872e_46dc_091c_0877_a50b5dcb058e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/resources/completions.py lines 49–152
def create(
self,
*,
max_tokens_to_sample: int,
model: ModelParam,
prompt: str,
metadata: MetadataParam | Omit = omit,
stop_sequences: SequenceNotStr[str] | Omit = omit,
stream: Literal[False] | Omit = omit,
temperature: float | Omit = omit,
top_k: int | Omit = omit,
top_p: float | Omit = omit,
betas: List[AnthropicBetaParam] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Completion:
"""[Legacy] Create a Text Completion.
The Text Completions API is a legacy API.
We recommend using the
[Messages API](https://docs.claude.com/en/api/messages) going forward.
Future models and features will not be compatible with Text Completions. See our
[migration guide](https://docs.claude.com/en/api/migrating-from-text-completions-to-messages)
for guidance in migrating from Text Completions to Messages.
Args:
max_tokens_to_sample: 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: The model that will complete your prompt.\n\nSee
[models](https://docs.anthropic.com/en/docs/models-overview) for additional
details and options.
prompt: 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://docs.claude.com/en/api/prompt-validation) and
our guide to [prompt design](https://docs.claude.com/en/docs/intro-to-prompting)
for more details.
metadata: An object describing metadata about the request.
stop_sequences: 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.
stream: Whether to incrementally stream the response using server-sent events.
See [streaming](https://docs.claude.com/en/api/streaming) for details.
temperature: 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: 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. You usually only need to use
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does create() do?
create() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/resources/completions.py.
Where is create() defined?
create() is defined in src/anthropic/resources/completions.py at line 49.
What does create() call?
create() calls 1 function(s): create.
What calls create()?
create() is called by 1 function(s): create.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free