[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
package main
import (
"context"
"fmt"
"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
)
func main() {
client := anthropic.NewClient(
option.WithAPIKey("my-anthropic-api-key"),
)
completion, err := client.Completions.New(context.TODO(), anthropic.CompletionNewParams{
MaxTokensToSample: 256,
Model: anthropic.ModelClaudeOpus4_5_20251101,
Prompt: "\n\nHuman: Hello, world!\n\nAssistant:",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", completion.ID)
}
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"
}