创建文本补全
POST/v1/complete
Deprecated: Use the Messages API instead.
[旧版] 创建文本补全。
Text Completions API 是旧版 API。我们建议今后使用 Messages API。
未来的模型和功能将不兼容 Text Completions。有关从 Text Completions 迁移到 Messages 的指导,请参阅我们的迁移指南。
Parameters
Returns
创建文本补全
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_HAIKU_5_5)
.prompt("\n\nHuman: Hello, world!\n\nAssistant:")
.build();
Completion completion = client.completions().create(params);
}
}Response 200
{
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"completion": " Hello! My name is Claude.",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
}Returns Examples
Response 200
{
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"completion": " Hello! My name is Claude.",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
}