[Legacy] Create a Text Completion. The Text Completions API is a legacy API. We recommend using the [Messages API](https://platform.claude.com/docs/en/api/messages) going forward. Future models and features will not be compatible with Text Completions. See our
(
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,
)
| 47 | |
| 48 | @overload |
| 49 | def create( |
| 50 | self, |
| 51 | *, |
| 52 | max_tokens_to_sample: int, |
| 53 | model: ModelParam, |
| 54 | prompt: str, |
| 55 | metadata: MetadataParam | Omit = omit, |
| 56 | stop_sequences: SequenceNotStr[str] | Omit = omit, |
| 57 | stream: Literal[False] | Omit = omit, |
| 58 | temperature: float | Omit = omit, |
| 59 | top_k: int | Omit = omit, |
| 60 | top_p: float | Omit = omit, |
| 61 | betas: List[AnthropicBetaParam] | Omit = omit, |
| 62 | class="cm"># Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 63 | class="cm"># The extra values given here take precedence over values defined on the client or passed to this method. |
| 64 | extra_headers: Headers | None = None, |
| 65 | extra_query: Query | None = None, |
| 66 | extra_body: Body | None = None, |
| 67 | timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 68 | ) -> Completion: |
| 69 | class="st">"""[Legacy] Create a Text Completion. |
| 70 | |
| 71 | The Text Completions API is a legacy API. |
| 72 | |
| 73 | We recommend using the |
| 74 | [Messages API](https://platform.claude.com/docs/en/api/messages) going forward. |
| 75 | |
| 76 | Future models and features will not be compatible with Text Completions. See our |
| 77 | [migration guide](https://platform.claude.com/docs/en/build-with-claude/working-with-messages) |
| 78 | for guidance in migrating from Text Completions to Messages. |
| 79 | |
| 80 | Args: |
| 81 | max_tokens_to_sample: The maximum number of tokens to generate before stopping. |
| 82 | |
| 83 | Note that our models may stop _before_ reaching this maximum. This parameter |
| 84 | only specifies the absolute maximum number of tokens to generate. |
| 85 | |
| 86 | model: The model that will complete your prompt. |
| 87 | |
| 88 | See [models](https://docs.anthropic.com/en/docs/models-overview) for additional |
| 89 | details and options. |
| 90 | |
| 91 | prompt: The prompt that you want Claude to complete. |
| 92 | |
| 93 | For proper response generation you will need to format your prompt using |
| 94 | alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example: |
| 95 | |
| 96 | ``` |
| 97 | class="st">"\n\nHuman: {userQuestion}\n\nAssistant:" |
| 98 | ``` |
| 99 | |
| 100 | See |
| 101 | [prompt validation](https://platform.claude.com/docs/en/build-with-claude/working-with-messages) |
| 102 | and our guide to |
| 103 | [prompt design](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/overview) |
| 104 | for more details. |
| 105 | |
| 106 | metadata: An object describing metadata about the request. |