Create a Text Completion
Completion completions().create(CompletionCreateParamsparams, RequestOptionsrequestOptions = RequestOptions.none())
/v1/complete
[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.
Parameters
Returns
Create a Text Completion
Java
package com.anthropic.example;
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
import com.anthropic.models.completions.Completion;
import com.anthropic.models.completions.CompletionCreateParams;
import com.anthropic.models.messages.Model;
public final class Main {
private Main() {}
public static void main(String[] args) {
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
CompletionCreateParams params = CompletionCreateParams.builder()
.maxTokensToSample(256L)
.model(Model.CLAUDE_3_7_SONNET_LATEST)
.prompt("\n\nHuman: Hello, world!\n\nAssistant:")
.build();
Completion completion = client.completions().create(params);
}
}{
"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"
}