Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build LLM-powered apps with the Anthropic Claude API or SDK across Python, TypeScript, Java, Go, Ruby, C#, and PHP.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
csharp/claude-api/streaming.md
1# Streaming — C#23## Streaming45```csharp6using Anthropic.Models.Messages;78var parameters = new MessageCreateParams9{10Model = Model.ClaudeOpus4_8,11MaxTokens = 64000,12Messages = [new() { Role = Role.User, Content = "Write a haiku" }]13};1415await foreach (RawMessageStreamEvent streamEvent in client.Messages.CreateStreaming(parameters))16{17if (streamEvent.TryPickContentBlockDelta(out var delta) &&18delta.Delta.TryPickText(out var text))19{20Console.Write(text.Text);21}22}23```2425**`RawMessageStreamEvent` TryPick methods** (naming drops the `Message`/`Raw` prefix): `TryPickStart`, `TryPickDelta`, `TryPickStop`, `TryPickContentBlockStart`, `TryPickContentBlockDelta`, `TryPickContentBlockStop`. There is no `TryPickMessageStop` — use `TryPickStop`.2627---2829