Anthropic::Completions
[Legacy] Text Completions API resource.
The Text Completions API is a legacy API; prefer client.messages for
new code. Future models and features will not be compatible with Text
Completions.
completion = client.completions.create(
model: "claude-haiku-4-5-20251001",
prompt: "\n\nHuman: Hello!\n\nAssistant:",
max_tokens_to_sample: 256
)
puts completion.completion
Constructors
new(client : Client)
SourceInstance methods
create(model : String, prompt : String, max_tokens_to_sample : Int32, metadata : Metadata | Nil = nil, stop_sequences : Array(String) | Nil = nil, temperature : Float64 | Nil = nil, top_k : Int32 | Nil = nil, top_p : Float64 | Nil = nil, stream : Bool = false, betas : Array(String) | Nil = nil, workspace_id : String | Nil = nil, extra_headers : Hash(String, String) | Nil = nil) : Completion
Create a text completion (non-streaming).
Raises ArgumentError when stream is true; use #stream instead
(mirrors the official Ruby/TypeScript SDKs).
stream(model : String, prompt : String, max_tokens_to_sample : Int32, metadata : Metadata | Nil = nil, stop_sequences : Array(String) | Nil = nil, temperature : Float64 | Nil = nil, top_k : Int32 | Nil = nil, top_p : Float64 | Nil = nil, stream : Bool = true, betas : Array(String) | Nil = nil, workspace_id : String | Nil = nil, extra_headers : Hash(String, String) | Nil = nil, & : Completion -> _)
Create a streaming text completion, yielding each Completion chunk.
client.completions.stream(
model: "claude-haiku-4-5-20251001",
prompt: "\n\nHuman: Hello!\n\nAssistant:",
max_tokens_to_sample: 256
) do |chunk|
print chunk.completion
end
Raises ArgumentError when stream is false; use #create instead.