Completions Class — anthropic-sdk-python Architecture
Architecture documentation for the Completions class in completions.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 3f9319c4_6f30_5159_c278_2ec1abd634e9["Completions"] 32bd9d9e_8b62_b229_7718_45771b424c40["SyncAPIResource"] 3f9319c4_6f30_5159_c278_2ec1abd634e9 -->|extends| 32bd9d9e_8b62_b229_7718_45771b424c40 f5340606_93f4_b0e0_a723_bb2136763e51["completions.py"] 3f9319c4_6f30_5159_c278_2ec1abd634e9 -->|defined in| f5340606_93f4_b0e0_a723_bb2136763e51 e7dc1bf7_d881_2795_1238_000f2f830977["with_raw_response()"] 3f9319c4_6f30_5159_c278_2ec1abd634e9 -->|method| e7dc1bf7_d881_2795_1238_000f2f830977 751fd0b5_cd08_e771_3202_d410143f4f9f["with_streaming_response()"] 3f9319c4_6f30_5159_c278_2ec1abd634e9 -->|method| 751fd0b5_cd08_e771_3202_d410143f4f9f 1ad0872e_46dc_091c_0877_a50b5dcb058e["create()"] 3f9319c4_6f30_5159_c278_2ec1abd634e9 -->|method| 1ad0872e_46dc_091c_0877_a50b5dcb058e
Relationship Graph
Source Code
src/anthropic/resources/completions.py lines 28–417
class Completions(SyncAPIResource):
@cached_property
def with_raw_response(self) -> CompletionsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
"""
return CompletionsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> CompletionsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
"""
return CompletionsWithStreamingResponse(self)
@overload
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
Domain
Defined In
Extends
Source
Frequently Asked Questions
What is the Completions class?
Completions is a class in the anthropic-sdk-python codebase, defined in src/anthropic/resources/completions.py.
Where is Completions defined?
Completions is defined in src/anthropic/resources/completions.py at line 28.
What does Completions extend?
Completions extends SyncAPIResource.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free