Skip to content

Beta streaming

This example assumes using Anthropic; is in scope and apiKey contains your Anthropic API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using var client = new AnthropicClient(apiKey);

var enumerable = client.CreateBetaMessageAsStreamAsync(
    new BetaCreateMessageParams
    {
        Model = "claude-sonnet-5-5",
        Messages = ["Once upon a time"],
        MaxTokens = 250,
        // Effort is the first cost lever: it trades thoroughness against token spend
        // within one model.
        OutputConfig = new BetaOutputConfig
        {
            Effort = BetaEffortLevel.Low,
        },
    });

var deltas = new List<string>();
await foreach (var response in enumerable)
{
    Console.Write(response.ContentBlockDelta?.Delta.TextDelta?.Text);

    deltas.Add(response.ContentBlockDelta?.Delta.TextDelta?.Text ?? string.Empty);
}