One read of Claude Developer Platformapi-20261021T163725Z
121 pages moved out of 808 read.
Pages moved
121
significant first
Pages read
808
in this capture
Captured
16:37 UTC
Corpus hash
8d3bd0be75f5
corpus-hash
What this read moved
26-50 of 121, page 2 of 5This capture is too large to show at once. Changes 26-50 of 121 are below, significant first; the rest are on the following screens.
build-with-claude/claude-in-amazon-bedrock Changed · +5 / -5 lines
from line 102
102102 <Tabs>
103103 <Tab title="Gradle">
104104 ```kotlin
105 implementation("com.anthropic:anthropic-java:2.75.0")
106 implementation("com.anthropic:anthropic-java-bedrock:2.75.0")
105 implementation("com.anthropic:anthropic-java:3.0.0")
106 implementation("com.anthropic:anthropic-java-bedrock:3.0.0")
107107 ```
108108 </Tab>
109109
from line 112
112112 <dependency>
113113 <groupId>com.anthropic</groupId>
114114 <artifactId>anthropic-java</artifactId>
115 <version>2.75.0</version>
115 <version>3.0.0</version>
116116 </dependency>
117117 <dependency>
118118 <groupId>com.anthropic</groupId>
119119 <artifactId>anthropic-java-bedrock</artifactId>
120 <version>2.75.0</version>
120 <version>3.0.0</version>
121121 </dependency>
122122 ```
123123 </Tab>
from line 216
216216 {
217217 Model = "anthropic.claude-opus-5-5",
218218 MaxTokens = 1024,
219 Messages = [new() { Role = Role.User, Content = "Hello, Claude" }],
219 Messages = [new UserMessageParam { Content = "Hello, Claude" }],
220220 });
221221
222222 foreach (var item in message.Content)
build-with-claude/claude-in-microsoft-foundry Changed · +6 / -6 lines
from line 80
8080 <Tabs>
8181 <Tab title="Gradle">
8282 ```kotlin
83 implementation("com.anthropic:anthropic-java:2.75.0")
84 implementation("com.anthropic:anthropic-java-foundry:2.75.0")
83 implementation("com.anthropic:anthropic-java:3.0.0")
84 implementation("com.anthropic:anthropic-java-foundry:3.0.0")
8585
8686 // For Entra ID authentication, also add the Azure Identity library
8787 implementation("com.azure:azure-identity:1.18.3")
from line 93
9393 <dependency>
9494 <groupId>com.anthropic</groupId>
9595 <artifactId>anthropic-java</artifactId>
96 <version>2.75.0</version>
96 <version>3.0.0</version>
9797 </dependency>
9898 <dependency>
9999 <groupId>com.anthropic</groupId>
100100 <artifactId>anthropic-java-foundry</artifactId>
101 <version>2.75.0</version>
101 <version>3.0.0</version>
102102 </dependency>
103103 <!-- For Entra ID authentication, also add the Azure Identity library -->
104104 <dependency>
from line 272
272272 {
273273 Model = "claude-opus-5-5",
274274 MaxTokens = 1024,
275 Messages = [new() { Role = Role.User, Content = "Hello!" }],
275 Messages = [new UserMessageParam { Content = "Hello!" }],
276276 });
277277
278278 Console.WriteLine(
from line 489
489489 {
490490 Model = "claude-opus-5-5",
491491 MaxTokens = 1024,
492 Messages = [new() { Role = Role.User, Content = "Hello!" }],
492 Messages = [new UserMessageParam { Content = "Hello!" }],
493493 });
494494
495495 Console.WriteLine(
build-with-claude/claude-on-amazon-bedrock-legacy Changed · +4 / -4 lines
from line 54
5454 <Tab title="Java">
5555 <CodeGroup>
5656 ```groovy Gradle
57 implementation("com.anthropic:anthropic-java:2.75.0")
58 implementation("com.anthropic:anthropic-java-bedrock:2.75.0")
57 implementation("com.anthropic:anthropic-java:3.0.0")
58 implementation("com.anthropic:anthropic-java-bedrock:3.0.0")
5959 ```
6060
6161 ```xml Maven
from line 62
6262 <dependency>
6363 <groupId>com.anthropic</groupId>
6464 <artifactId>anthropic-java</artifactId>
65 <version>2.75.0</version>
65 <version>3.0.0</version>
6666 </dependency>
6767 <dependency>
6868 <groupId>com.anthropic</groupId>
6969 <artifactId>anthropic-java-bedrock</artifactId>
70 <version>2.75.0</version>
70 <version>3.0.0</version>
7171 </dependency>
7272 ```
7373
build-with-claude/claude-on-vertex-ai Changed · +8 / -8 lines
from line 45
4545 <Tab title="Java">
4646 <CodeGroup exclude="shell, python, typescript, csharp, go, php, ruby">
4747 ```groovy Gradle
48 implementation("com.anthropic:anthropic-java:2.75.0")
49 implementation("com.anthropic:anthropic-java-vertex:2.75.0")
48 implementation("com.anthropic:anthropic-java:3.0.0")
49 implementation("com.anthropic:anthropic-java-vertex:3.0.0")
5050 ```
5151
5252 ```xml Maven
from line 53
5353 <dependency>
5454 <groupId>com.anthropic</groupId>
5555 <artifactId>anthropic-java</artifactId>
56 <version>2.75.0</version>
56 <version>3.0.0</version>
5757 </dependency>
5858 <dependency>
5959 <groupId>com.anthropic</groupId>
6060 <artifactId>anthropic-java-vertex</artifactId>
61 <version>2.75.0</version>
61 <version>3.0.0</version>
6262 </dependency>
6363 ```
6464
from line 238
238238 {
239239 Model = Model.ClaudeOpus5_5,
240240 MaxTokens = 100,
241 Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
241 Messages = [new UserMessageParam { Content = "Hey Claude!" }]
242242 };
243243
244244 var message = await client.Messages.Create(parameters);
from line 510
510510 {
511511 Model = Model.ClaudeOpus5_5,
512512 MaxTokens = 100,
513 Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
513 Messages = [new UserMessageParam { Content = "Hey Claude!" }]
514514 };
515515
516516 var message = await client.Messages.Create(parameters);
from line 696
696696 {
697697 Model = Model.ClaudeOpus5_5,
698698 MaxTokens = 100,
699 Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
699 Messages = [new UserMessageParam { Content = "Hey Claude!" }]
700700 };
701701
702702 var message = await client.Messages.Create(parameters);
from line 886
886886 // Specific regional endpoints support Claude Sonnet 4.6 and earlier; newer models use the global or multi-region endpoints
887887 Model = Model.ClaudeSonnet4_6,
888888 MaxTokens = 100,
889 Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
889 Messages = [new UserMessageParam { Content = "Hey Claude!" }]
890890 };
891891
892892 var message = await client.Messages.Create(parameters);
build-with-claude/claude-platform-on-aws Changed · +7 / -7 lines
from line 305
305305
306306 <Tab title="Java">
307307 ```kotlin Gradle
308 implementation("com.anthropic:anthropic-java:2.75.0")
309 implementation("com.anthropic:anthropic-java-aws:2.75.0")
308 implementation("com.anthropic:anthropic-java:3.0.0")
309 implementation("com.anthropic:anthropic-java-aws:3.0.0")
310310 ```
311311
312312 ```xml Maven
from line 313
313313 <dependency>
314314 <groupId>com.anthropic</groupId>
315315 <artifactId>anthropic-java</artifactId>
316 <version>2.75.0</version>
316 <version>3.0.0</version>
317317 </dependency>
318318 <dependency>
319319 <groupId>com.anthropic</groupId>
320320 <artifactId>anthropic-java-aws</artifactId>
321 <version>2.75.0</version>
321 <version>3.0.0</version>
322322 </dependency>
323323 ```
324324 </Tab>
from line 453
453453 {
454454 Model = Model.ClaudeSonnet5_5,
455455 MaxTokens = 1024,
456 Messages = [new() { Role = Role.User, Content = "Hello!" }]
456 Messages = [new UserMessageParam { Content = "Hello!" }]
457457 });
458458
459459 Console.WriteLine(message);
from line 678
678678 Model = Model.ClaudeSonnet5_5,
679679 MaxTokens = 1024,
680680 InferenceGeo = "us",
681 Messages = [new() { Role = Role.User, Content = "Hello!" }]
681 Messages = [new UserMessageParam { Content = "Hello!" }]
682682 });
683683
684684 Console.WriteLine(message);
from line 963
963963 {
964964 Model = Model.ClaudeSonnet5_5,
965965 MaxTokens = 1024,
966 Messages = [new() { Role = Role.User, Content = "Hello!" }]
966 Messages = [new UserMessageParam { Content = "Hello!" }]
967967 });
968968
969969 Console.WriteLine(response.Headers.GetValues("x-amzn-requestid").First()); // AWS request ID
build-with-claude/compaction-background Changed · +4 / -9 lines
from line 241
241241 // Replace exactly the messages the compaction request held. Later turns stay after the block.
242242 return
243243 [
244 new()
244 new BetaAssistantMessageParam
245245 {
246 Role = Role.Assistant,
247246 Content = summary.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
248247 },
249248 .. history[sent..],
from line 261
262261 pending = null;
263262 }
264263
265 history.Add(new() { Role = Role.User, Content = question });
264 history.Add(new BetaUserMessageParam { Content = question });
266265 var response = await client.Beta.Messages.Create(new MessageCreateParams
267266 {
268267 Model = Model.ClaudeOpus5_5,
from line 270
271270 Betas = [AnthropicBeta.Compact2026_09_04],
272271 Messages = history,
273272 });
274 history.Add(new()
273 history.Add(new BetaAssistantMessageParam
275274 {
276 Role = Role.Assistant,
277275 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
278276 });
279277
from line 428
430428 pending = null;
431429 }
432430
433 history.add(BetaMessageParam.builder()
434 .role(BetaMessageParam.Role.USER)
435 .content(questions.get(turn - 1))
436 .build());
431 history.add(BetaMessageParam.ofUser(questions.get(turn - 1)));
437432 var params = MessageCreateParams.builder()
438433 .model(Model.CLAUDE_OPUS_5_5)
439434 .maxTokens(8192)
build-with-claude/compaction-keep-recent-turns Changed · +4 / -9 lines
from line 203
203203 foreach (var (index, question) in questions.Index())
204204 {
205205 var turn = index + 1;
206 history.Add(new() { Role = Role.User, Content = question });
206 history.Add(new BetaUserMessageParam { Content = question });
207207 var response = await client.Beta.Messages.Create(new MessageCreateParams
208208 {
209209 Model = Model.ClaudeOpus5_5,
from line 212
212212 Betas = [AnthropicBeta.Compact2026_09_04],
213213 Messages = history,
214214 });
215 history.Add(new()
215 history.Add(new BetaAssistantMessageParam
216216 {
217 Role = Role.Assistant,
218217 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
219218 });
220219
from line 237
238237 {
239238 history =
240239 [
241 new()
240 new BetaAssistantMessageParam
242241 {
243 Role = Role.Assistant,
244242 Content = summary.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
245243 },
246244 .. recent,
from line 340
342340
343341 var history = new ArrayList<BetaMessageParam>();
344342 for (int turn = 1; turn <= questions.size(); turn++) {
345 history.add(BetaMessageParam.builder()
346 .role(BetaMessageParam.Role.USER)
347 .content(questions.get(turn - 1))
348 .build());
343 history.add(BetaMessageParam.ofUser(questions.get(turn - 1)));
349344 var params = MessageCreateParams.builder()
350345 .model(Model.CLAUDE_OPUS_5_5)
351346 .maxTokens(8192)
build-with-claude/compaction-on-demand Changed · +7 / -14 lines
from line 146
146146
147147 List<BetaMessageParam> history =
148148 [
149 new()
149 new BetaUserMessageParam
150150 {
151 Role = Role.User,
152151 Content = "I am building a recipe app. Help me name the main entities in the data model.",
153152 },
154 new()
153 new BetaAssistantMessageParam
155154 {
156 Role = Role.Assistant,
157155 Content = "Start with Recipe, Ingredient, and Step. Add a RecipeIngredient entry that holds the quantity and unit for each ingredient in a recipe.",
158156 },
159 new() { Role = Role.User, Content = "Good. Now suggest field names for Recipe." },
157 new BetaUserMessageParam { Content = "Good. Now suggest field names for Recipe." },
160158 ];
161159
162160 var response = await client.Beta.Messages.Create(new MessageCreateParams
from line 489
491489 foreach (var (index, question) in questions.Index())
492490 {
493491 var turn = index + 1;
494 history.Add(new() { Role = Role.User, Content = question });
492 history.Add(new BetaUserMessageParam { Content = question });
495493 var response = await client.Beta.Messages.Create(new MessageCreateParams
496494 {
497495 Model = Model.ClaudeOpus5_5,
from line 498
500498 Betas = [AnthropicBeta.Compact2026_09_04],
501499 Messages = history,
502500 });
503 history.Add(new()
501 history.Add(new BetaAssistantMessageParam
504502 {
505 Role = Role.Assistant,
506503 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
507504 });
508505
from line 520
523520 {
524521 history =
525522 [
526 new()
523 new BetaAssistantMessageParam
527524 {
528 Role = Role.Assistant,
529525 Content = summary.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
530526 },
531527 ];
from line 617
621617
622618 var history = new ArrayList<BetaMessageParam>();
623619 for (int turn = 1; turn <= questions.size(); turn++) {
624 history.add(BetaMessageParam.builder()
625 .role(BetaMessageParam.Role.USER)
626 .content(questions.get(turn - 1))
627 .build());
620 history.add(BetaMessageParam.ofUser(questions.get(turn - 1)));
628621 var params = MessageCreateParams.builder()
629622 .model(Model.CLAUDE_OPUS_5_5)
630623 .maxTokens(8192)
build-with-claude/compaction-thinking-blocks Changed · +10 / -22 lines
from line 252
252252 // 1. Have a short conversation with thinking on.
253253 List<BetaMessageParam> history =
254254 [
255 new() { Role = Role.User, Content = "What are the main entities in the app's data model?" },
255 new BetaUserMessageParam { Content = "What are the main entities in the app's data model?" },
256256 ];
257257 var first = await client.Beta.Messages.Create(new MessageCreateParams
258258 {
from line 265
265265 });
266266 history.AddRange(
267267 [
268 new()
268 new BetaAssistantMessageParam
269269 {
270 Role = Role.Assistant,
271270 Content = first.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
272271 },
273 new()
272 new BetaUserMessageParam
274273 {
275 Role = Role.User,
276274 Content = "Testing starts on Tuesday, March 3, 2026, takes 10 weekdays, and pauses on March 9 and March 16. On which date does it end?",
277275 },
278276 ]);
from line 283
285283 Thinking = thinking,
286284 Messages = history,
287285 });
288 history.Add(new()
286 history.Add(new BetaAssistantMessageParam
289287 {
290 Role = Role.Assistant,
291288 Content = second.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
292289 });
293290 var thinkingBlocks = second.Content.Count(block => block.TryPickThinking(out _));
from line 309
312309 // 3. Put the block in front of the kept turn and ask the next question.
313310 history =
314311 [
315 new()
312 new BetaAssistantMessageParam
316313 {
317 Role = Role.Assistant,
318314 Content = summary.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
319315 },
320316 .. history[2..],
321 new() { Role = Role.User, Content = "Which day should the release go out?" },
317 new BetaUserMessageParam { Content = "Which day should the release go out?" },
322318 ];
323319 var third = await client.Beta.Messages.Create(new MessageCreateParams
324320 {
from line 460
464460
465461 // 1. Have a short conversation with thinking on.
466462 var history = new ArrayList<BetaMessageParam>();
467 history.add(BetaMessageParam.builder()
468 .role(BetaMessageParam.Role.USER)
469 .content("What are the main entities in the app's data model?")
470 .build());
463 history.add(BetaMessageParam.ofUser("What are the main entities in the app's data model?"));
471464 var firstParams = MessageCreateParams.builder()
472465 .model(MODEL)
473466 .maxTokens(8192)
from line 471
478471 .build();
479472 var first = client.beta().messages().create(firstParams);
480473 history.add(first.toParam());
481 history.add(BetaMessageParam.builder()
482 .role(BetaMessageParam.Role.USER)
483 .content("Testing starts on Tuesday, March 3, 2026, takes 10 weekdays, and pauses on March 9 and March 16. On which date does it end?")
484 .build());
474 history.add(BetaMessageParam.ofUser(
475 "Testing starts on Tuesday, March 3, 2026, takes 10 weekdays, and pauses on March 9 and March 16. On which date does it end?"));
485476 var secondParams = MessageCreateParams.builder()
486477 .model(MODEL)
487478 .maxTokens(8192)
from line 505
514505 // 3. Put the block in front of the kept turn and ask the next question.
515506 firstTurn.clear();
516507 history.addFirst(summary.toParam());
517 history.add(BetaMessageParam.builder()
518 .role(BetaMessageParam.Role.USER)
519 .content("Which day should the release go out?")
520 .build());
508 history.add(BetaMessageParam.ofUser("Which day should the release go out?"));
521509 var thirdParams = MessageCreateParams.builder()
522510 .model(MODEL)
523511 .maxTokens(8192)
build-with-claude/compaction-threshold Changed · +51 / -66 lines
from line 152
152152
153153 var messages = new List<BetaMessageParam>
154154 {
155 new() { Role = Role.User, Content = "Help me build a website" }
155 new BetaUserMessageParam { Content = "Help me build a website" }
156156 };
157157
158158 var parameters = new MessageCreateParams
from line 170
170170 var response = await client.Beta.Messages.Create(parameters);
171171
172172 // Append the response (including any compaction block) to continue the conversation
173 messages.Add(new BetaMessageParam
173 messages.Add(new BetaAssistantMessageParam
174174 {
175 Role = Role.Assistant,
176175 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList()
177176 });
178177
from line 383
384383
385384 ```csharp C#
386385 AnthropicClient client = new();
387 List<BetaMessageParam> messages = [new() { Role = Role.User, Content = "Hello" }];
386 List<BetaMessageParam> messages = [new BetaUserMessageParam { Content = "Hello" }];
388387
389388 var parameters = new MessageCreateParams
390389 {
from line 607
608607 MaxTokens = 4096,
609608 Messages =
610609 [
611 new BetaMessageParam { Role = Role.User, Content = "Help me build a Python web scraper" },
612 new BetaMessageParam { Role = Role.Assistant, Content = "I'll help you build a web scraper..." },
613 new BetaMessageParam { Role = Role.User, Content = "Add support for JavaScript-rendered pages" }
610 new BetaUserMessageParam { Content = "Help me build a Python web scraper" },
611 new BetaAssistantMessageParam { Content = "I'll help you build a web scraper..." },
612 new BetaUserMessageParam { Content = "Add support for JavaScript-rendered pages" }
614613 ],
615614 ContextManagement = new BetaContextManagementConfig
616615 {
from line 857
858857 var client = new AnthropicClient();
859858 var messages = new List<BetaMessageParam>
860859 {
861 new() { Role = Role.User, Content = "Hello, Claude" }
860 new BetaUserMessageParam { Content = "Hello, Claude" }
862861 };
863862
864863 var parameters = new MessageCreateParams
from line 879
880879
881880 if (response.StopReason == BetaStopReason.Compaction)
882881 {
883 messages.Add(new BetaMessageParam
882 messages.Add(new BetaAssistantMessageParam
884883 {
885 Role = Role.Assistant,
886884 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList()
887885 });
888886
from line 1153
11551153
11561154 ```csharp C#
11571155 AnthropicClient client = new();
1158 List<BetaMessageParam> messages = [new() { Role = Role.User, Content = "Hello, Claude" }];
1156 List<BetaMessageParam> messages = [new BetaUserMessageParam { Content = "Hello, Claude" }];
11591157
11601158 const int TriggerThreshold = 100_000;
11611159 const int TotalTokenBudget = 3_000_000;
from line 1178
11801178 if (response.StopReason == BetaStopReason.Compaction)
11811179 {
11821180 compactionCount += 1;
1183 messages.Add(new()
1181 messages.Add(new BetaAssistantMessageParam
11841182 {
1185 Role = Role.Assistant,
11861183 Content = response.Content.Select(b => new BetaContentBlockParam(b.Json)).ToList()
11871184 });
11881185
from line 1186
11891186 // Estimate total tokens consumed; prompt wrap-up if over budget
11901187 if (compactionCount * TriggerThreshold >= TotalTokenBudget)
11911188 {
1192 messages.Add(new()
1189 messages.Add(new BetaUserMessageParam
11931190 {
1194 Role = Role.User,
11951191 Content = "Please wrap up your current work and summarize the final state."
11961192 });
11971193 }
from line 1248
12521248 int compactionCount = 0;
12531249
12541250 List<BetaMessageParam> messages = new ArrayList<>();
1255 messages.add(BetaMessageParam.builder()
1256 .role(BetaMessageParam.Role.USER)
1257 .content("Hello, Claude")
1258 .build());
1251 messages.add(BetaMessageParam.ofUser("Hello, Claude"));
12591252
12601253 MessageCreateParams params = MessageCreateParams.builder()
12611254 .addBeta("compact-2026-01-12")
from line 1274
12811274
12821275 // Estimate total tokens consumed; prompt wrap-up if over budget
12831276 if (compactionCount * triggerThreshold >= totalTokenBudget) {
1284 messages.add(BetaMessageParam.builder()
1285 .role(BetaMessageParam.Role.USER)
1286 .content("Please wrap up your current work and summarize the final state.")
1287 .build());
1277 messages.add(BetaMessageParam.ofUser(
1278 "Please wrap up your current work and summarize the final state."));
12881279 }
12891280 }
12901281
from line 1459
14681459
14691460 var messages = new List<BetaMessageParam>
14701461 {
1471 new() { Role = Role.User, Content = "Help me build a web scraper" }
1462 new BetaUserMessageParam { Content = "Help me build a web scraper" }
14721463 };
14731464
14741465 var response = await client.Beta.Messages.Create(new()
from line 1474
14831474 }
14841475 });
14851476
1486 messages.Add(new BetaMessageParam
1477 messages.Add(new BetaAssistantMessageParam
14871478 {
1488 Role = Role.Assistant,
14891479 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList()
14901480 });
14911481
1492 messages.Add(new BetaMessageParam { Role = Role.User, Content = "Now add error handling" });
1482 messages.Add(new BetaUserMessageParam { Content = "Now add error handling" });
14931483
14941484 var nextResponse = await client.Beta.Messages.Create(new()
14951485 {
from line 1784
17941784
17951785 ```csharp C#
17961786 var client = new AnthropicClient();
1797 List<BetaMessageParam> messages = [new() { Role = Role.User, Content = "Hello" }];
1787 List<BetaMessageParam> messages = [new BetaUserMessageParam { Content = "Hello" }];
17981788
17991789 var parameters = new MessageCreateParams
18001790 {
from line 2133
21432133 CacheControl = new BetaCacheControlEphemeral()
21442134 }
21452135 },
2146 Messages = [new() { Role = Role.User, Content = "Hello, Claude" }],
2136 Messages = [new BetaUserMessageParam { Content = "Hello, Claude" }],
21472137 ContextManagement = new BetaContextManagementConfig
21482138 {
21492139 Edits = [new BetaCompact20260112Edit()]
from line 2367
23772367
23782368 ```csharp C#
23792369 AnthropicClient client = new();
2380 List<BetaMessageParam> messages = [new() { Role = Role.User, Content = "Hello" }];
2370 List<BetaMessageParam> messages = [new BetaUserMessageParam { Content = "Hello" }];
23812371
23822372 var countParams = new MessageCountTokensParams
23832373 {
from line 2565
25752565
25762566 static async Task<string> Chat(AnthropicClient client, List<BetaMessageParam> messages, string userMessage)
25772567 {
2578 messages.Add(new() { Role = Role.User, Content = userMessage });
2568 messages.Add(new BetaUserMessageParam { Content = userMessage });
25792569
25802570 var parameters = new MessageCreateParams
25812571 {
from line 2584
25942584
25952585 var response = await client.Beta.Messages.Create(parameters);
25962586
2597 messages.Add(new()
2587 messages.Add(new BetaAssistantMessageParam
25982588 {
2599 Role = Role.Assistant,
26002589 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList()
26012590 });
26022591
from line 2665
26762665 }
26772666
26782667 private static String chat(String userMessage) {
2679 messages.add(BetaMessageParam.builder()
2680 .role(BetaMessageParam.Role.USER)
2681 .content(userMessage)
2682 .build());
2668 messages.add(BetaMessageParam.ofUser(userMessage));
26832669
26842670 MessageCreateParams params = MessageCreateParams.builder()
26852671 .addBeta("compact-2026-01-12")
from line 2952
29662952
29672953 async Task<string> Chat(string userMessage)
29682954 {
2969 messages.Add(new() { Role = Role.User, Content = userMessage });
2955 messages.Add(new BetaUserMessageParam { Content = userMessage });
29702956
29712957 var response = await client.Beta.Messages.Create(new()
29722958 {
from line 2977
29912977
29922978 // Preserve the prior exchange + current user message (3 messages),
29932979 // without thinking blocks; an assistant turn left empty is dropped
2994 var preserved = messages
2995 .Skip(Math.Max(0, messages.Count - 3))
2996 .Select(message => message.Content.TryPickBetaContentBlockParams(out var blocks)
2997 ? new BetaMessageParam
2998 {
2999 Role = message.Role,
3000 Content = blocks
3001 .Where(block => block.Type.GetString() is not ("thinking" or "redacted_thinking"))
3002 .ToList()
3003 }
3004 : message)
3005 .Where(message => !message.Content.TryPickBetaContentBlockParams(out var blocks) || blocks.Count > 0)
3006 .ToList();
2980 var preserved = new List<BetaMessageParam>();
2981 foreach (var message in messages.Skip(Math.Max(0, messages.Count - 3)))
2982 {
2983 if (!message.TryPickAssistant(out var assistant)
2984 || !assistant.Content.TryPickBetaContentBlockParams(out var blocks))
2985 {
2986 preserved.Add(message);
2987 continue;
2988 }
30072989
2990 var kept = blocks
2991 .Where(block => block.Type.Raw() is not ("thinking" or "redacted_thinking"))
2992 .ToList();
2993 if (kept.Count > 0)
2994 {
2995 preserved.Add(assistant with { Content = kept });
2996 }
2997 }
2998
30082999 var messagesAfterCompaction = new List<BetaMessageParam>
30093000 {
3010 new()
3001 new BetaAssistantMessageParam
30113002 {
3012 Role = Role.Assistant,
30133003 Content = new List<BetaContentBlockParam> { new BetaContentBlockParam(response.Content[0].Json) }
30143004 }
30153005 };
from line 3020
30303020 messages = messagesAfterCompaction;
30313021 }
30323022
3033 messages.Add(new()
3023 messages.Add(new BetaAssistantMessageParam
30343024 {
3035 Role = Role.Assistant,
30363025 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList()
30373026 });
30383027
from line 3142
31533142 private static final List<BetaMessageParam> messages = new ArrayList<>();
31543143
31553144 public static String chat(String userMessage) {
3156 messages.add(BetaMessageParam.builder()
3157 .role(BetaMessageParam.Role.USER)
3158 .content(userMessage)
3159 .build());
3145 messages.add(BetaMessageParam.ofUser(userMessage));
31603146
31613147 MessageCreateParams params = MessageCreateParams.builder()
31623148 .addBeta("compact-2026-01-12")
from line 3168
31823168 // without thinking blocks; an assistant turn left empty is dropped
31833169 List<BetaMessageParam> preservedMessages = new ArrayList<>();
31843170 for (BetaMessageParam message : messages.subList(Math.max(0, messages.size() - 3), messages.size())) {
3185 if (message.content().isBetaContentBlockParams()) {
3186 message = message.toBuilder()
3187 .contentOfBetaContentBlockParams(message.content().asBetaContentBlockParams().stream()
3188 .filter(block -> !block.isThinking() && !block.isRedactedThinking())
3189 .toList())
3190 .build();
3191 if (message.content().asBetaContentBlockParams().isEmpty()) {
3171 if (message.isAssistant() && message.asAssistant().content().isContentBlockParams()) {
3172 var keptBlocks = message.asAssistant().content().asContentBlockParams().stream()
3173 .filter(block -> !block.isThinking() && !block.isRedactedThinking())
3174 .toList();
3175 if (keptBlocks.isEmpty()) {
31923176 continue;
31933177 }
3178 message = BetaMessageParam.ofAssistantOfContentBlockParams(keptBlocks);
31943179 }
31953180 preservedMessages.add(message);
31963181 }
build-with-claude/context-editing Changed · +8 / -18 lines
from line 176
176176 {
177177 Model = Messages::Model.ClaudeOpus5_5,
178178 MaxTokens = 4096,
179 Messages = [
180 new() { Role = Role.User, Content = "Search for recent developments in AI" }
181 ],
179 Messages = [new BetaUserMessageParam { Content = "Search for recent developments in AI" }],
182180 Tools = [
183181 new BetaWebSearchTool20250305()
184182 ],
from line 479
481479 Model = Messages::Model.ClaudeOpus5_5,
482480 MaxTokens = 4096,
483481 Messages = [
484 new() { Role = Role.User, Content = "Create a simple command line calculator app using Python" }
482 new BetaUserMessageParam { Content = "Create a simple command line calculator app using Python" }
485483 ],
486484 Tools = [
487485 new BetaToolTextEditor20250728 { MaxCharacters = 10000 },
from line 790
792790 {
793791 Model = Messages::Model.ClaudeOpus5_5,
794792 MaxTokens = 16000,
795 Messages = [
796 new() { Role = Role.User, Content = "Hello" }
797 ],
793 Messages = [new BetaUserMessageParam { Content = "Hello" }],
798794 Betas = [AnthropicBeta.ContextManagement2025_06_27],
799795 ContextManagement = new BetaContextManagementConfig
800796 {
from line 1019
10231019 {
10241020 Model = Messages::Model.ClaudeOpus5_5,
10251021 MaxTokens = 16000,
1026 Messages = [
1027 new() { Role = Role.User, Content = "Hello" }
1028 ],
1022 Messages = [new BetaUserMessageParam { Content = "Hello" }],
10291023 Betas = [AnthropicBeta.ContextManagement2025_06_27],
10301024 ContextManagement = new BetaContextManagementConfig
10311025 {
from line 1223
12291223 {
12301224 Model = Messages::Model.ClaudeOpus5_5,
12311225 MaxTokens = 16000,
1232 Messages = [
1233 new() { Role = Role.User, Content = "Hello" }
1234 ],
1226 Messages = [new BetaUserMessageParam { Content = "Hello" }],
12351227 Betas = [AnthropicBeta.ContextManagement2025_06_27],
12361228 ContextManagement = new BetaContextManagementConfig
12371229 {
from line 1511
15191511 Model = Messages::Model.ClaudeOpus5_5,
15201512 MaxTokens = 16000,
15211513 Messages = [
1522 new() { Role = Role.User, Content = "Search for the latest developments in quantum error correction and summarize the key breakthroughs." }
1514 new BetaUserMessageParam { Content = "Search for the latest developments in quantum error correction and summarize the key breakthroughs." }
15231515 ],
15241516 Tools = [
15251517 new BetaWebSearchTool20250305 { MaxUses = 5 }
from line 1913
19211913 var parameters = new MessageCountTokensParams
19221914 {
19231915 Model = Messages::Model.ClaudeOpus5_5,
1924 Messages = [new() { Role = Role.User, Content = "Continue our conversation..." }],
1916 Messages = [new BetaUserMessageParam { Content = "Continue our conversation..." }],
19251917 Betas = [AnthropicBeta.ContextManagement2025_06_27],
19261918 ContextManagement = new BetaContextManagementConfig
19271919 {
from line 2184
21922184 {
21932185 Model = Messages::Model.ClaudeOpus5_5,
21942186 MaxTokens = 4096,
2195 Messages = [
2196 new() { Role = Role.User, Content = "Hello" }
2197 ],
2187 Messages = [new BetaUserMessageParam { Content = "Hello" }],
21982188 Tools = [
21992189 new BetaMemoryTool20250818()
22002190 ],
build-with-claude/effort Changed · +8 / -11 lines
from line 117
117117 Model = Model.ClaudeOpus5_5,
118118 MaxTokens = 4096,
119119 Messages = [
120 new() {
121 Role = Role.User,
120 new UserMessageParam {
122121 Content = "Analyze the trade-offs between microservices and monolithic architectures"
123122 }
124123 ],
from line 495
496495 OutputConfig = new() { Effort = Effort.High },
497496 Messages =
498497 [
499 new() { Role = Role.User, Content = "Plan a migration from SQLite to PostgreSQL in three short steps." },
500 new() { Role = Role.Assistant, Content = "1. Export the SQLite data. 2. Create the PostgreSQL schema. 3. Import the data and verify row counts." },
498 new BetaUserMessageParam { Content = "Plan a migration from SQLite to PostgreSQL in three short steps." },
499 new BetaAssistantMessageParam { Content = "1. Export the SQLite data. 2. Create the PostgreSQL schema. 3. Import the data and verify row counts." },
501500 // Effort-only system message: the new level takes effect from the next user turn.
502 new()
501 new BetaSystemMessageParam
503502 {
504 Role = Role.System,
505503 Content = new([]),
506504 OutputConfig = new() { Effort = BetaSystemMessageOutputConfigEffort.Low },
507505 },
508 new() { Role = Role.User, Content = "Summarize the plan in one sentence." },
506 new BetaUserMessageParam { Content = "Summarize the plan in one sentence." },
509507 ],
510508 Betas = [AnthropicBeta.MidConversationOutputConfig2026_07_01],
511509 });
from line 554
556554 ```java Java
557555 import com.anthropic.models.beta.AnthropicBeta;
558556 import com.anthropic.models.beta.messages.BetaMessage;
559 import com.anthropic.models.beta.messages.BetaMessageParam;
560557 import com.anthropic.models.beta.messages.BetaOutputConfig;
561558 import com.anthropic.models.beta.messages.BetaSystemMessageOutputConfig;
559 import com.anthropic.models.beta.messages.BetaSystemMessageParam;
562560 import com.anthropic.models.beta.messages.MessageCreateParams;
563561 import com.anthropic.models.messages.Model;
564562
from line 573
575573 .addUserMessage("Plan a migration from SQLite to PostgreSQL in three short steps.")
576574 .addAssistantMessage("1. Export the SQLite data. 2. Create the PostgreSQL schema. 3. Import the data and verify row counts.")
577575 // Effort-only system message: the new level takes effect from the next user turn.
578 .addMessage(BetaMessageParam.builder()
579 .role(BetaMessageParam.Role.SYSTEM)
580 .contentOfBetaContentBlockParams(List.of())
576 .addMessage(BetaSystemMessageParam.builder()
577 .contentOfBlocks(List.of())
581578 .outputConfig(BetaSystemMessageOutputConfig.builder()
582579 .effort(BetaSystemMessageOutputConfig.Effort.LOW)
583580 .build())
build-with-claude/fallback-credit Changed · +4 / -8 lines
from line 189
189189 var client = new AnthropicClient();
190190 const string beta = "fallback-credit-2026-07-01";
191191
192 List<BetaMessageParam> requestMessages =
193 [
194 new() { Role = Role.User, Content = "Hello, Claude" },
195 ];
192 List<BetaMessageParam> requestMessages = [new BetaUserMessageParam { Content = "Hello, Claude" }];
196193 MessageCreateParams Request(Model model) => new()
197194 {
198195 Model = model,
from line 223
226223 Messages =
227224 [
228225 .. requestMessages,
229 new()
226 new BetaAssistantMessageParam
230227 {
231 Role = Role.Assistant,
232 Content = new BetaMessageParamContent(
228 Content = new BetaMessageContentParam(
233229 JsonSerializer.SerializeToElement(echoed)
234230 ),
235231 },
from line 366
370366 echoed.addLast(BetaContentBlockParam.ofText(
371367 lastText.toBuilder().text(lastText.text().stripTrailing()).build()));
372368 }
373 attempt.addAssistantMessageOfBetaContentBlockParams(echoed);
369 attempt.addAssistantMessageOfContentBlockParams(echoed);
374370 }
375371 try {
376372 response = send(Model.CLAUDE_OPUS_4_8, attempt);
build-with-claude/fast-mode Changed · +3 / -3 lines
from line 108
108108 MaxTokens = 4096,
109109 Speed = Speed.Fast,
110110 Messages = [
111 new() { Role = Role.User, Content = "Refactor this module to use dependency injection" }
111 new UserMessageParam { Content = "Refactor this module to use dependency injection" }
112112 ],
113113 });
114114
from line 309
309309 Model = Model.ClaudeOpus5_5,
310310 MaxTokens = 1024,
311311 Speed = Speed.Fast,
312 Messages = [new() { Role = Role.User, Content = "Hello" }],
312 Messages = [new UserMessageParam { Content = "Hello" }],
313313 });
314314
315315 Console.WriteLine(response.Usage.Speed); // "fast" or "standard"
from line 518
518518 {
519519 Model = Model.ClaudeOpus5_5,
520520 MaxTokens = 1024,
521 Messages = [new() { Role = Role.User, Content = "Hello" }],
521 Messages = [new UserMessageParam { Content = "Hello" }],
522522 Speed = Speed.Fast,
523523 },
524524 maxRetries: 0);
build-with-claude/files Changed · +3 / -5 lines
from line 266
266266 MaxTokens = 1024,
267267 Messages =
268268 [
269 new MessageParam
269 new UserMessageParam
270270 {
271 Role = Role.User,
272271 Content = new List<ContentBlockParam>
273272 {
274273 new TextBlockParam { Text = "Please summarize this document for me." },
from line 308
309308 MessageCreateParams params = MessageCreateParams.builder()
310309 .model(Model.CLAUDE_OPUS_5_5)
311310 .maxTokens(1024)
312 .addUserMessageOfBlockParams(List.of(
311 .addUserMessageOfContentBlockParams(List.of(
313312 ContentBlockParam.ofText(TextBlockParam.builder()
314313 .text("Please summarize this document for me.")
315314 .build()),
from line 542
543542 {
544543 Model = Model.ClaudeOpus5_5,
545544 MaxTokens = 1024,
546 Messages = [new()
545 Messages = [new UserMessageParam
547546 {
548 Role = Role.User,
549547 Content = $"Here's the document content:\n\n{textContent}\n\nPlease summarize this document."
550548 }]
551549 };
build-with-claude/handling-stop-reasons Changed · +50 / -70 lines
from line 109
109109 {
110110 Model = Model.ClaudeOpus5_5,
111111 MaxTokens = 1024,
112 Messages = [new() { Role = Role.User, Content = "Hello!" }]
112 Messages = [new UserMessageParam { Content = "Hello!" }]
113113 });
114114
115115 if (response.StopReason == "end_turn")
from line 323
323323 // INCORRECT: Adding text immediately after tool_result
324324 List<MessageParam> messages =
325325 [
326 new() { Role = Role.User, Content = "Calculate the sum of 1234 and 5678" },
327 new()
326 new UserMessageParam { Content = "Calculate the sum of 1234 and 5678" },
327 new AssistantMessageParam
328328 {
329 Role = Role.Assistant,
330329 Content = new List<ContentBlockParam>
331330 {
332331 new ToolUseBlockParam { ID = "toolu_123", Name = "calculator", Input = input }
333332 }
334333 },
335 new()
334 new UserMessageParam
336335 {
337 Role = Role.User,
338336 Content = new List<ContentBlockParam>
339337 {
340338 new ToolResultBlockParam { ToolUseID = "toolu_123", Content = "6912" },
from line 344
346344 // CORRECT: Send tool results directly without additional text
347345 messages =
348346 [
349 new() { Role = Role.User, Content = "Calculate the sum of 1234 and 5678" },
350 new()
347 new UserMessageParam { Content = "Calculate the sum of 1234 and 5678" },
348 new AssistantMessageParam
351349 {
352 Role = Role.Assistant,
353350 Content = new List<ContentBlockParam>
354351 {
355352 new ToolUseBlockParam { ID = "toolu_123", Name = "calculator", Input = input }
356353 }
357354 },
358 new()
355 new UserMessageParam
359356 {
360 Role = Role.User,
361357 // Just the tool_result, no additional text
362358 Content = new List<ContentBlockParam>
363359 {
from line 404
408404
409405 // INCORRECT: Adding text immediately after tool_result
410406 List<MessageParam> messages = List.of(
411 MessageParam.builder().role(MessageParam.Role.USER)
412 .content("Calculate the sum of 1234 and 5678").build(),
413 MessageParam.builder().role(MessageParam.Role.ASSISTANT)
414 .contentOfBlockParams(List.of(ContentBlockParam.ofToolUse(toolUse))).build(),
415 MessageParam.builder().role(MessageParam.Role.USER)
416 .contentOfBlockParams(List.of(
417 ContentBlockParam.ofToolResult(
418 ToolResultBlockParam.builder().toolUseId("toolu_123").content("6912").build()),
419 // Don't add text after tool_result
420 ContentBlockParam.ofText(TextBlockParam.builder().text("Here's the result").build())
421 )).build()
407 MessageParam.ofUser("Calculate the sum of 1234 and 5678"),
408 MessageParam.ofAssistantOfContentBlockParams(List.of(ContentBlockParam.ofToolUse(toolUse))),
409 MessageParam.ofUserOfContentBlockParams(List.of(
410 ContentBlockParam.ofToolResult(
411 ToolResultBlockParam.builder().toolUseId("toolu_123").content("6912").build()),
412 // Don't add text after tool_result
413 ContentBlockParam.ofText(TextBlockParam.builder().text("Here's the result").build())
414 ))
422415 );
423416
424417 // CORRECT: Send tool results directly without additional text
425418 messages = List.of(
426 MessageParam.builder().role(MessageParam.Role.USER)
427 .content("Calculate the sum of 1234 and 5678").build(),
428 MessageParam.builder().role(MessageParam.Role.ASSISTANT)
429 .contentOfBlockParams(List.of(ContentBlockParam.ofToolUse(toolUse))).build(),
419 MessageParam.ofUser("Calculate the sum of 1234 and 5678"),
420 MessageParam.ofAssistantOfContentBlockParams(List.of(ContentBlockParam.ofToolUse(toolUse))),
430421 // Just the tool_result, no additional text
431 MessageParam.builder().role(MessageParam.Role.USER)
432 .contentOfBlockParams(List.of(
433 ContentBlockParam.ofToolResult(
434 ToolResultBlockParam.builder().toolUseId("toolu_123").content("6912").build())
435 )).build()
422 MessageParam.ofUserOfContentBlockParams(List.of(
423 ContentBlockParam.ofToolResult(
424 ToolResultBlockParam.builder().toolUseId("toolu_123").content("6912").build())
425 ))
436426 );
437427 ```
438428
from line 593
603593 if (response.StopReason == "end_turn" && response.Content.Count == 0)
604594 {
605595 // CORRECT: Add a continuation prompt in a NEW user message
606 messages.Add(new() { Role = Role.User, Content = "Please continue" });
596 messages.Add(new UserMessageParam { Content = "Please continue" });
607597
608598 response = await client.Messages.Create(new MessageCreateParams
609599 {
from line 652
662652 if (isEndTurn && response.content().isEmpty()) {
663653 // CORRECT: Add a continuation prompt in a NEW user message
664654 List<MessageParam> extended = new ArrayList<>(messages);
665 extended.add(MessageParam.builder()
666 .role(MessageParam.Role.USER)
667 .content("Please continue")
668 .build());
655 extended.add(MessageParam.ofUser("Please continue"));
669656
670657 response = client.messages().create(
671658 MessageCreateParams.builder()
from line 788
801788 {
802789 Model = Model.ClaudeOpus5_5,
803790 MaxTokens = 10,
804 Messages = [new() { Role = Role.User, Content = "Explain quantum physics" }]
791 Messages = [new UserMessageParam { Content = "Explain quantum physics" }]
805792 });
806793
807794 if (response.StopReason == "max_tokens")
from line 1098
11111098 Model = Model.ClaudeOpus5_5,
11121099 MaxTokens = 1024,
11131100 StopSequences = ["END", "STOP"],
1114 Messages = [new() { Role = Role.User, Content = "Generate text until you say END" }]
1101 Messages = [new UserMessageParam { Content = "Generate text until you say END" }]
11151102 });
11161103
11171104 if (response.StopReason == "stop_sequence")
from line 1319
13321319 Model = Model.ClaudeOpus5_5,
13331320 MaxTokens = 1024,
13341321 Tools = [weatherTool],
1335 Messages = [new() { Role = Role.User, Content = "What is the weather in San Francisco?" }]
1322 Messages = [new UserMessageParam { Content = "What is the weather in San Francisco?" }]
13361323 });
13371324
13381325 if (response.StopReason == "tool_use")
from line 1600
16131600
16141601 ```csharp C#
16151602 List<ToolUnion> tools = [new ToolUnion(new WebSearchTool20250305())];
1616 MessageParam userMessage = new() { Role = Role.User, Content = "Search for latest AI news" };
1603 MessageParam userMessage = new UserMessageParam { Content = "Search for latest AI news" };
16171604
16181605 var response = await client.Messages.Create(new MessageCreateParams
16191606 {
from line 1621
16341621 Messages =
16351622 [
16361623 userMessage,
1637 new()
1624 new AssistantMessageParam
16381625 {
1639 Role = Role.Assistant,
16401626 Content = response.Content.Select(block => new ContentBlockParam(block.Json)).ToList()
16411627 }
16421628 ]
from line 1802
18161802 {
18171803 Model = Model.ClaudeOpus5_5,
18181804 MaxTokens = 1024,
1819 Messages = [new() { Role = Role.User, Content = "[Unsafe request]" }]
1805 Messages = [new UserMessageParam { Content = "[Unsafe request]" }]
18201806 });
18211807
18221808 if (response.StopReason == "refusal")
from line 1961
19751961 {
19761962 Model = Model.ClaudeOpus5_5,
19771963 MaxTokens = 20000,
1978 Messages = [new() { Role = Role.User, Content = "Large input that uses most of context window..." }]
1964 Messages = [new BetaUserMessageParam { Content = "Large input that uses most of context window..." }]
19791965 });
19801966
19811967 if (response.StopReason?.Value() == BetaStopReason.ModelContextWindowExceeded)
from line 2396
24102396 List<ToolUnion> tools,
24112397 int maxContinuations = 5)
24122398 {
2413 List<MessageParam> messages = [new() { Role = Role.User, Content = userQuery }];
2399 List<MessageParam> messages = [new UserMessageParam { Content = userQuery }];
24142400 Message response = null!;
24152401
24162402 for (var i = 0; i < maxContinuations; i++)
from line 2418
24322418 // pause_turn: replace the full message list to maintain alternating roles
24332419 messages =
24342420 [
2435 new() { Role = Role.User, Content = userQuery },
2436 new()
2421 new UserMessageParam { Content = userQuery },
2422 new AssistantMessageParam
24372423 {
2438 Role = Role.Assistant,
24392424 Content = response.Content.Select(block => new ContentBlockParam(block.Json)).ToList()
24402425 }
24412426 ];
from line 2674
26892674 {
26902675 Model = Model.ClaudeOpus5_5,
26912676 MaxTokens = 1024,
2692 Messages = [new() { Role = Role.User, Content = "Hello!" }]
2677 Messages = [new UserMessageParam { Content = "Hello!" }]
26932678 });
26942679
26952680 // Handle successful response with stop_reason
from line 2864
28792864 {
28802865 Model = Model.ClaudeOpus5_5,
28812866 MaxTokens = 1024,
2882 Messages = [new() { Role = Role.User, Content = "Hello!" }]
2867 Messages = [new UserMessageParam { Content = "Hello!" }]
28832868 };
28842869
28852870 await foreach (var streamEvent in client.Messages.CreateStreaming(parameters))
from line 3025
30403025 string userQuery,
30413026 List<ToolUnion> tools)
30423027 {
3043 List<MessageParam> messages = [new() { Role = Role.User, Content = userQuery }];
3028 List<MessageParam> messages = [new UserMessageParam { Content = userQuery }];
30443029
30453030 while (true)
30463031 {
from line 3041
30563041 {
30573042 // Execute tools and continue
30583043 var toolResults = ExecuteTools(response.Content);
3059 messages.Add(new()
3044 messages.Add(new AssistantMessageParam
30603045 {
3061 Role = Role.Assistant,
30623046 Content = response.Content.Select(block => new ContentBlockParam(block.Json)).ToList()
30633047 });
3064 messages.Add(new() { Role = Role.User, Content = toolResults });
3048 messages.Add(new UserMessageParam { Content = toolResults });
30653049 }
30663050 else
30673051 {
from line 3099
31153099 List<Tool> tools
31163100 ) {
31173101 List<MessageParam> messages = new ArrayList<>();
3118 messages.add(MessageParam.builder().role(MessageParam.Role.USER).content(userQuery).build());
3102 messages.add(MessageParam.ofUser(userQuery));
31193103
31203104 while (true) {
31213105 MessageCreateParams.Builder params = MessageCreateParams.builder()
from line 3118
31343118 // Execute tools and continue
31353119 List<ToolResultBlockParam> toolResults = executeTools(response.content());
31363120 messages.add(response.toParam());
3137 messages.add(MessageParam.builder()
3138 .role(MessageParam.Role.USER)
3139 .contentOfBlockParams(toolResults.stream().map(ContentBlockParam::ofToolResult).toList())
3140 .build());
3121 messages.add(MessageParam.ofUserOfContentBlockParams(
3122 toolResults.stream().map(ContentBlockParam::ofToolResult).toList()));
31413123 }
31423124 }
31433125 ```
from line 3242
32603242 ```csharp C#
32613243 static async Task<string> GetCompleteResponse(AnthropicClient client, string prompt, int maxAttempts = 3)
32623244 {
3263 List<MessageParam> messages = [new() { Role = Role.User, Content = prompt }];
3245 List<MessageParam> messages = [new UserMessageParam { Content = prompt }];
32643246 var fullResponse = "";
32653247
32663248 for (var i = 0; i < maxAttempts; i++)
from line 3271
32893271 // Continue from where it left off
32903272 messages =
32913273 [
3292 new() { Role = Role.User, Content = prompt },
3293 new() { Role = Role.Assistant, Content = fullResponse },
3294 new() { Role = Role.User, Content = "Please continue from where you left off." }
3274 new UserMessageParam { Content = prompt },
3275 new AssistantMessageParam { Content = fullResponse },
3276 new UserMessageParam { Content = "Please continue from where you left off." }
32953277 ];
32963278 }
32973279
from line 3321
33393321
33403322 ```java Java
33413323 static String getCompleteResponse(AnthropicClient client, String prompt, int maxAttempts) {
3342 List<MessageParam> messages = List.of(
3343 MessageParam.builder().role(MessageParam.Role.USER).content(prompt).build()
3344 );
3324 List<MessageParam> messages = List.of(MessageParam.ofUser(prompt));
33453325 StringBuilder fullResponse = new StringBuilder();
33463326
33473327 for (int i = 0; i < maxAttempts; i++) {
from line 3344
33643344
33653345 // Continue from where it left off
33663346 messages = List.of(
3367 MessageParam.builder().role(MessageParam.Role.USER).content(prompt).build(),
3368 MessageParam.builder().role(MessageParam.Role.ASSISTANT).content(fullResponse.toString()).build(),
3369 MessageParam.builder().role(MessageParam.Role.USER).content("Please continue from where you left off.").build()
3347 MessageParam.ofUser(prompt),
3348 MessageParam.ofAssistant(fullResponse.toString()),
3349 MessageParam.ofUser("Please continue from where you left off.")
33703350 );
33713351 }
33723352
from line 3489
35093489 {
35103490 Model = Model.ClaudeOpus5_5,
35113491 MaxTokens = 20000,
3512 Messages = [new() { Role = Role.User, Content = prompt }]
3492 Messages = [new BetaUserMessageParam { Content = prompt }]
35133493 });
35143494
35153495 var tokens = response.Usage.OutputTokens;
build-with-claude/mid-conversation-effort-example Changed · +12 / -23 lines
from line 1548
15481548 "You are one agent in a larger parallel fan-out, assigned a single subtask. "
15491549 + "Investigate it directly, using bash to check facts rather than guessing, and finish "
15501550 + "by calling report_findings exactly once. Return findings, not narration.";
1551 List<MessageParam> messages = [new() { Role = Role.User, Content = prompt }];
1551 List<MessageParam> messages = [new UserMessageParam { Content = prompt }];
15521552 for (var turn = 0; turn < maxSubagentTurns; turn++)
15531553 {
15541554 using var deadline = new CancellationTokenSource(TimeSpan.FromSeconds(requestTimeoutSeconds));
from line 1561
15611561 Tools = [bashTool, reportTool],
15621562 Messages = messages,
15631563 }, cancellationToken: deadline.Token).Aggregate();
1564 messages.Add(new()
1564 messages.Add(new AssistantMessageParam
15651565 {
1566 Role = Role.Assistant,
15671566 Content = response.Content.Select(block => new ContentBlockParam(block.Json)).ToList(),
15681567 });
15691568 if (response.StopReason == StopReason.PauseTurn)
from line 1603
16041603 {
16051604 return report;
16061605 }
1607 messages.Add(new() { Role = Role.User, Content = toolResults });
1606 messages.Add(new UserMessageParam { Content = toolResults });
16081607 }
16091608 return "(subagent hit the turn limit before finishing)";
16101609 }
from line 1713
17141713 // Subagents inherit the main loop's effort level.
17151714 String runSubagent(Model model, String prompt) throws InterruptedException {
17161715 List<MessageParam> messages = new ArrayList<>();
1717 messages.add(MessageParam.builder().role(MessageParam.Role.USER).content(prompt).build());
1716 messages.add(MessageParam.ofUser(prompt));
17181717 for (int turn = 0; turn < MAX_SUBAGENT_TURNS; turn++) {
17191718 MessageCreateParams params = MessageCreateParams.builder()
17201719 .model(model)
from line 1767
17681767 if (report != null) {
17691768 return report;
17701769 }
1771 messages.add(MessageParam.builder()
1772 .role(MessageParam.Role.USER)
1773 .contentOfBlockParams(toolResults)
1774 .build());
1770 messages.add(MessageParam.ofUserOfContentBlockParams(toolResults));
17751771 }
17761772 return "(subagent hit the turn limit before finishing)";
17771773 }
from line 3201
32053201 modeOn = nextModeOn;
32063202 }
32073203
3208 MessageParam SystemMessage(string content) => new() { Role = Role.System, Content = content };
3204 MessageParam SystemMessage(string content) => new SystemMessageParam { Content = content };
32093205
32103206 // System messages owed on this turn: an exit notice, the full mode text on entry,
32113207 // or a one-line refresher every turnsBetweenRefreshers user turns.
from line 3236
32403236 {
32413237 // Mid-conversation system messages follow the user turn they apply to, which keeps
32423238 // the cached prefix ahead of them untouched.
3243 messages.Add(new() { Role = Role.User, Content = userInput });
3239 messages.Add(new UserMessageParam { Content = userInput });
32443240 messages.AddRange(DueSystemMessages());
32453241 turnsSinceReminder++;
32463242
from line 3252
32563252 Tools = [workflowTool, bashTool],
32573253 Messages = messages,
32583254 }, cancellationToken: deadline.Token).Aggregate();
3259 messages.Add(new()
3255 messages.Add(new AssistantMessageParam
32603256 {
3261 Role = Role.Assistant,
32623257 Content = response.Content.Select(block => new ContentBlockParam(block.Json)).ToList(),
32633258 });
32643259
from line 3289
32943289 };
32953290 toolResults.Add(new ToolResultBlockParam(toolUse.ID) { Content = output, IsError = isError });
32963291 }
3297 messages.Add(new() { Role = Role.User, Content = toolResults });
3292 messages.Add(new UserMessageParam { Content = toolResults });
32983293 }
32993294 return "(hit the main loop turn limit before finishing)";
33003295 }
from line 3471
34763471 }
34773472
34783473 private MessageParam systemMessage(String content) {
3479 return MessageParam.builder()
3480 .role(MessageParam.Role.SYSTEM)
3481 .content(content)
3482 .build();
3474 return MessageParam.ofSystem(content);
34833475 }
34843476
34853477 // Send one user turn through the loop, executing tool calls until the model stops.
from line 3478
34863478 String turn(String userInput) throws InterruptedException {
34873479 // Mid-conversation system messages follow the user turn they apply to, which keeps
34883480 // the cached prefix ahead of them untouched.
3489 messages.add(MessageParam.builder().role(MessageParam.Role.USER).content(userInput).build());
3481 messages.add(MessageParam.ofUser(userInput));
34903482 messages.addAll(dueSystemMessages());
34913483 turnsSinceReminder++;
34923484
from line 3533
35413533 .isError(result.isError())
35423534 .build()));
35433535 }
3544 messages.add(MessageParam.builder()
3545 .role(MessageParam.Role.USER)
3546 .contentOfBlockParams(toolResults)
3547 .build());
3536 messages.add(MessageParam.ofUserOfContentBlockParams(toolResults));
35483537 }
35493538 return "(hit the main loop turn limit before finishing)";
35503539 }
build-with-claude/mid-conversation-system-messages Changed · +33 / -57 lines
from line 228
228228 ],
229229 Messages =
230230 [
231 new() { Role = Role.User, Content = "Say OK." },
231 new BetaUserMessageParam { Content = "Say OK." },
232232 // Withdraw get_weather from this point onward. The block references
233233 // the tool by name instead of editing `Tools`, so earlier turns stay
234234 // byte-identical and the cache still hits.
235 new()
235 new BetaSystemMessageParam
236236 {
237 Role = Role.System,
238237 Content = new(
239238 [
240239 new BetaRequestToolRemovalBlock
from line 306
307306
308307 ```java Java
309308 import com.anthropic.models.beta.AnthropicBeta;
310 import com.anthropic.models.beta.messages.BetaContentBlockParam;
311309 import com.anthropic.models.beta.messages.BetaMessage;
312 import com.anthropic.models.beta.messages.BetaMessageParam;
313310 import com.anthropic.models.beta.messages.BetaRequestToolRemovalBlock;
311 import com.anthropic.models.beta.messages.BetaSystemMessageParam.Content.SystemMessageContentBlock;
314312 import com.anthropic.models.beta.messages.BetaTool;
315313 import com.anthropic.models.beta.messages.MessageCreateParams;
316314 // ...
from line 338
340338 // Withdraw get_weather from this point onward. The block references
341339 // the tool by name instead of editing `tools`, so earlier turns stay
342340 // byte-identical and the cache still hits.
343 .addMessage(BetaMessageParam.builder()
344 .role(BetaMessageParam.Role.SYSTEM)
345 .contentOfBetaContentBlockParams(List.of(
346 BetaContentBlockParam.ofToolRemoval(BetaRequestToolRemovalBlock.builder()
347 .referenceTool("get_weather")
348 .build())))
349 .build())
341 .addSystemMessageOfBlocks(List.of(
342 SystemMessageContentBlock.ofToolRemoval(BetaRequestToolRemovalBlock.builder()
343 .referenceTool("get_weather")
344 .build())))
350345 .build();
351346
352347 BetaMessage response = client.beta().messages().create(params);
from line 714
719714 ],
720715 Messages =
721716 [
722 new() { Role = Role.User, Content = "How many orders shipped yesterday?" },
717 new BetaUserMessageParam { Content = "How many orders shipped yesterday?" },
723718 // Define db_query by value from this point onward. `Tools` and the
724719 // earlier messages stay exactly as sent, so the cache still hits.
725 new()
720 new BetaSystemMessageParam
726721 {
727 Role = Role.System,
728722 Content = new(
729723 [
730724 new BetaRequestToolAdditionBlock
from line 814
820814
821815 ```java Java
822816 import com.anthropic.models.beta.AnthropicBeta;
823 import com.anthropic.models.beta.messages.BetaContentBlockParam;
824817 import com.anthropic.models.beta.messages.BetaMessage;
825818 import com.anthropic.models.beta.messages.BetaRequestToolAdditionBlock;
819 import com.anthropic.models.beta.messages.BetaSystemMessageParam.Content.SystemMessageContentBlock;
826820 import com.anthropic.models.beta.messages.BetaTool;
827821 import com.anthropic.models.beta.messages.MessageCreateParams;
828822 // ...
from line 858
864858 .addUserMessage("How many orders shipped yesterday?")
865859 // Define db_query by value from this point onward. `tools` and the
866860 // earlier messages stay exactly as sent, so the cache still hits.
867 .addSystemMessageOfBetaContentBlockParams(List.of(
868 BetaContentBlockParam.ofToolAddition(BetaRequestToolAdditionBlock.builder()
861 .addSystemMessageOfBlocks(List.of(
862 SystemMessageContentBlock.ofToolAddition(BetaRequestToolAdditionBlock.builder()
869863 .definitionTool(dbQueryTool)
870864 .build())))
871865 .build();
from line 1296
13021296 ],
13031297 Messages =
13041298 [
1305 new() { Role = Role.User, Content = "What's on my calendar tomorrow?" },
1299 new BetaUserMessageParam { Content = "What's on my calendar tomorrow?" },
13061300 // Make the calendar server's tools available from this point onward.
13071301 // The block names the server; it never holds a URL or token.
1308 new()
1302 new BetaSystemMessageParam
13091303 {
1310 Role = Role.System,
13111304 Content = new(
13121305 [
13131306 new BetaRequestToolAdditionBlock
from line 1400
14071400
14081401 ```java Java
14091402 import com.anthropic.models.beta.AnthropicBeta;
1410 import com.anthropic.models.beta.messages.BetaContentBlockParam;
14111403 import com.anthropic.models.beta.messages.BetaMcpTool;
14121404 import com.anthropic.models.beta.messages.BetaMcpToolset;
14131405 import com.anthropic.models.beta.messages.BetaMessage;
14141406 import com.anthropic.models.beta.messages.BetaRequestMcpServerUrlDefinition;
14151407 import com.anthropic.models.beta.messages.BetaRequestToolAdditionBlock;
1408 import com.anthropic.models.beta.messages.BetaSystemMessageParam.Content.SystemMessageContentBlock;
14161409 import com.anthropic.models.beta.messages.BetaTool;
14171410 import com.anthropic.models.beta.messages.MessageCreateParams;
14181411 // ...
from line 1440
14471440 .addUserMessage("What's on my calendar tomorrow?")
14481441 // Make the calendar server's tools available from this point onward.
14491442 // The block names the server; it never holds a URL or token.
1450 .addSystemMessageOfBetaContentBlockParams(List.of(
1451 BetaContentBlockParam.ofToolAddition(BetaRequestToolAdditionBlock.builder()
1443 .addSystemMessageOfBlocks(List.of(
1444 SystemMessageContentBlock.ofToolAddition(BetaRequestToolAdditionBlock.builder()
14521445 .definitionTool(BetaMcpToolset.builder()
14531446 .mcpServerName("calendar")
14541447 .build())
from line 1780
17871780 System = "You are a code review assistant. Be concise.",
17881781 Messages =
17891782 [
1790 new()
1783 new UserMessageParam { Content = "Review process() in utils.py for performance issues." },
1784 new AssistantMessageParam
17911785 {
1792 Role = Role.User,
1793 Content = "Review process() in utils.py for performance issues."
1794 },
1795 new()
1796 {
1797 Role = Role.Assistant,
17981786 Content = "The list comprehension is fine for small inputs. For large inputs, consider a generator to avoid materializing the full list."
17991787 },
1800 new()
1801 {
1802 Role = Role.User,
1803 Content = "Now review the calling code that invokes process()."
1804 },
1788 new UserMessageParam { Content = "Now review the calling code that invokes process()." },
18051789 // The reviewer realizes mid-session that all suggestions must also pass
18061790 // the team's strict typing policy. Appending the instruction here keeps
18071791 // earlier turns byte-identical, so the prefix cached by the previous
18081792 // request is still read from cache.
1809 new()
1793 new SystemMessageParam
18101794 {
1811 Role = Role.System,
18121795 Content = "From now on, every suggestion must include explicit type annotations."
18131796 }
18141797 ]
from line 1842
18591842 ```java Java
18601843 import com.anthropic.models.messages.CacheControlEphemeral;
18611844 // ...
1862 import com.anthropic.models.messages.MessageParam;
1863 // ...
18641845 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
18651846
18661847 MessageCreateParams params = MessageCreateParams.builder()
from line 1858
18771858 // the team's strict typing policy. Appending the instruction here keeps
18781859 // earlier turns byte-identical, so the prefix cached by the previous
18791860 // request is still read from cache.
1880 .addMessage(MessageParam.builder()
1881 .role(MessageParam.Role.SYSTEM)
1882 .content("From now on, every suggestion must include explicit type annotations.")
1883 .build())
1861 .addSystemMessage("From now on, every suggestion must include explicit type annotations.")
18841862 .build();
18851863
18861864 Message response = client.messages().create(params);
from line 2194
22162194 MaxTokens = 4096,
22172195 Messages =
22182196 [
2219 new() { Role = Role.User, Content = "Draft a short status update on the database migration for the team channel." },
2197 new BetaUserMessageParam { Content = "Draft a short status update on the database migration for the team channel." },
22202198 // Turn-scoped reminder: renders for this turn, then clears once a later user message exists.
2221 new()
2199 new BetaSystemMessageParam
22222200 {
2223 Role = Role.System,
22242201 ClearAt = ClearAt.NextUserMessage,
22252202 Content = "The reader is on call: keep this reply under 50 words.",
22262203 },
from line 2245
22682245 ```java Java
22692246 import com.anthropic.models.beta.AnthropicBeta;
22702247 import com.anthropic.models.beta.messages.BetaMessage;
2271 import com.anthropic.models.beta.messages.BetaMessageParam;
2248 import com.anthropic.models.beta.messages.BetaSystemMessageParam;
22722249 import com.anthropic.models.beta.messages.MessageCreateParams;
22732250 import com.anthropic.models.messages.Model;
22742251
from line 2258
22812258 .addBeta(AnthropicBeta.MID_CONVERSATION_SYSTEM_CLEAR_AT_2026_08_21)
22822259 .addUserMessage("Draft a short status update on the database migration for the team channel.")
22832260 // Turn-scoped reminder: renders for this turn, then clears once a later user message exists.
2284 .addMessage(BetaMessageParam.builder()
2285 .role(BetaMessageParam.Role.SYSTEM)
2286 .clearAt(BetaMessageParam.ClearAt.NEXT_USER_MESSAGE)
2261 .addMessage(BetaSystemMessageParam.builder()
2262 .clearAt(BetaSystemMessageParam.ClearAt.NEXT_USER_MESSAGE)
22872263 .content("The reader is on call: keep this reply under 50 words.")
22882264 .build())
22892265 .build();
build-with-claude/multilingual-support Changed · +1 / -4 lines
from line 102
102102 Model = Model.ClaudeOpus5_5,
103103 MaxTokens = 1024,
104104 System = "Always respond in French, regardless of the language the user writes in.",
105 Messages =
106 [
107 new() { Role = Role.User, Content = "How do I reset my password?" }
108 ]
105 Messages = [new UserMessageParam { Content = "How do I reset my password?" }]
109106 };
110107
111108 var message = await client.Messages.Create(parameters);
build-with-claude/pdf-support Changed · +16 / -22 lines
from line 221
221221 MaxTokens = 1024,
222222 Messages =
223223 [
224 new()
224 new UserMessageParam
225225 {
226 Role = Role.User,
227226 Content = new List<ContentBlockParam>
228227 {
229228 documentParam,
from line 275
276275 MessageCreateParams params = MessageCreateParams.builder()
277276 .model(Model.CLAUDE_OPUS_5_5)
278277 .maxTokens(1024)
279 .addUserMessageOfBlockParams(
278 .addUserMessageOfContentBlockParams(
280279 List.of(
281280 ContentBlockParam.ofDocument(documentParam),
282281 ContentBlockParam.ofText(
from line 532
533532 MaxTokens = 1024,
534533 Messages =
535534 [
536 new()
535 new UserMessageParam
537536 {
538 Role = Role.User,
539537 Content = new List<ContentBlockParam>
540538 {
541539 documentParam,
from line 613
615613 MessageCreateParams params = MessageCreateParams.builder()
616614 .model(Model.CLAUDE_OPUS_5_5)
617615 .maxTokens(1024)
618 .addUserMessageOfBlockParams(
616 .addUserMessageOfContentBlockParams(
619617 List.of(
620618 ContentBlockParam.ofDocument(documentParam),
621619 ContentBlockParam.ofText(
from line 852
854852 MaxTokens = 1024,
855853 Messages =
856854 [
857 new()
855 new UserMessageParam
858856 {
859 Role = Role.User,
860857 Content = new List<ContentBlockParam>
861858 {
862859 new DocumentBlockParam
from line 918
921918 MessageCreateParams params = MessageCreateParams.builder()
922919 .model(Model.CLAUDE_OPUS_5_5)
923920 .maxTokens(1024)
924 .addUserMessageOfBlockParams(
921 .addUserMessageOfContentBlockParams(
925922 List.of(
926923 ContentBlockParam.ofDocument(
927924 DocumentBlockParam.builder().fileSource(file.id()).build()
from line 1197
12001197 MaxTokens = 1024,
12011198 Messages =
12021199 [
1203 new()
1200 new UserMessageParam
12041201 {
1205 Role = Role.User,
12061202 Content = new List<ContentBlockParam>
12071203 {
12081204 new DocumentBlockParam
from line 1275
12791275 MessageCreateParams params = MessageCreateParams.builder()
12801276 .model(Model.CLAUDE_OPUS_5_5)
12811277 .maxTokens(1024)
1282 .addUserMessageOfBlockParams(
1278 .addUserMessageOfContentBlockParams(
12831279 List.of(
12841280 ContentBlockParam.ofDocument(
12851281 DocumentBlockParam.builder()
from line 1635
16391635 MaxTokens = 1024,
16401636 Messages =
16411637 [
1642 new()
1638 new UserMessageParam
16431639 {
1644 Role = Role.User,
16451640 Content = new List<ContentBlockParam>
16461641 {
16471642 new DocumentBlockParam
from line 1658
16631658 MaxTokens = 1024,
16641659 Messages =
16651660 [
1666 new()
1661 new UserMessageParam
16671662 {
1668 Role = Role.User,
16691663 Content = new List<ContentBlockParam>
16701664 {
16711665 new DocumentBlockParam
from line 1758
17641758 BatchCreateParams.Request.Params.builder()
17651759 .model(Model.CLAUDE_OPUS_5_5)
17661760 .maxTokens(1024)
1767 .addUserMessageOfBlockParams(
1761 .addUserMessageOfContentBlockParams(
17681762 List.of(
17691763 ContentBlockParam.ofDocument(
17701764 DocumentBlockParam.builder()
from line 1785
17911785 BatchCreateParams.Request.Params.builder()
17921786 .model(Model.CLAUDE_OPUS_5_5)
17931787 .maxTokens(1024)
1794 .addUserMessageOfBlockParams(
1788 .addUserMessageOfContentBlockParams(
17951789 List.of(
17961790 ContentBlockParam.ofDocument(
17971791 DocumentBlockParam.builder()
build-with-claude/preserved-thinking Changed · +5 / -8 lines
from line 250
250250 },
251251 Messages =
252252 [
253 new()
253 new BetaUserMessageParam
254254 {
255 Role = Role.User,
256255 Content = "What is the greatest common divisor of 1071 and 462?",
257256 },
258257 ],
from line 535
536535 List<BetaMessageParam> messages = [];
537536 foreach (var userTurn in userTurns)
538537 {
539 messages.Add(new() { Role = Role.User, Content = userTurn });
538 messages.Add(new BetaUserMessageParam { Content = userTurn });
540539 var response = await client.Beta.Messages.Create(
541540 new()
542541 {
from line 552
553552 Betas = [AnthropicBeta.ThinkingBindingControls2026_08_01],
554553 }
555554 );
556 messages.Add(new()
555 messages.Add(new BetaAssistantMessageParam
557556 {
558 Role = Role.Assistant,
559557 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
560558 });
561559 var thinkingBlocks = response.Content.Count(block => block.TryPickThinking(out _));
from line 846
848846 List<BetaMessageParam> messages = [];
849847 for (var turnIndex = 0; turnIndex < userTurns.Length; turnIndex++)
850848 {
851 messages.Add(new() { Role = Role.User, Content = userTurns[turnIndex] });
849 messages.Add(new BetaUserMessageParam { Content = userTurns[turnIndex] });
852850 var response = await client.Beta.Messages.Create(
853851 new()
854852 {
from line 859
861859 Betas = [AnthropicBeta.ThinkingBindingControls2026_08_01],
862860 }
863861 );
864 messages.Add(new()
862 messages.Add(new BetaAssistantMessageParam
865863 {
866 Role = Role.Assistant,
867864 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
868865 });
869866 var thinkingBlocks = response.Content.Count(block => block.TryPickThinking(out _));
build-with-claude/prompt-caching Changed · +40 / -61 lines
from line 100
100100 System = "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.",
101101 Messages =
102102 [
103 new()
104 {
105 Role = Role.User,
106 Content = "Analyze the major themes in 'Pride and Prejudice'."
107 }
103 new UserMessageParam { Content = "Analyze the major themes in 'Pride and Prejudice'." }
108104 ]
109105 };
110106
from line 366
370366 System = "You are a helpful assistant that remembers our conversation.",
371367 Messages =
372368 [
373 new()
369 new UserMessageParam { Content = "My name is Alex. I work on machine learning." },
370 new AssistantMessageParam
374371 {
375 Role = Role.User,
376 Content = "My name is Alex. I work on machine learning."
377 },
378 new()
379 {
380 Role = Role.Assistant,
381372 Content = "Nice to meet you, Alex! How can I help with your ML work today?"
382373 },
383 new()
384 {
385 Role = Role.User,
386 Content = "What did I say I work on?"
387 }
374 new UserMessageParam { Content = "What did I say I work on?" }
388375 ]
389376 };
390377
from line 991
1004991 },
1005992 ]
1006993 ),
1007 Messages = [new() { Role = Role.User, Content = "warmup" }],
994 Messages = [new UserMessageParam { Content = "warmup" }],
1008995 }
1009996 );
1010997
from line 1304
13171304 Model = Model.ClaudeOpus5_5,
13181305 MaxTokens = 0,
13191306 System = new(systemPrompt),
1320 Messages = [new() { Role = Role.User, Content = "warmup" }],
1307 Messages = [new UserMessageParam { Content = "warmup" }],
13211308 }
13221309 );
13231310
from line 1316
13291316 Model = Model.ClaudeOpus5_5,
13301317 MaxTokens = 1024,
13311318 System = new(systemPrompt),
1332 Messages = [new() { Role = Role.User, Content = userMessage }],
1319 Messages = [new UserMessageParam { Content = userMessage }],
13331320 }
13341321 );
13351322
from line 1662
16751662 }),
16761663 Messages =
16771664 [
1678 new()
1665 new UserMessageParam
16791666 {
1680 Role = Role.User,
16811667 Content = "What are the key terms and conditions in this agreement?"
16821668 }
16831669 ]
from line 2031
20452031 }),
20462032 Messages =
20472033 [
2048 new()
2034 new UserMessageParam
20492035 {
2050 Role = Role.User,
2051 Content = new MessageParamContent(new List<ContentBlockParam>
2036 Content = new List<ContentBlockParam>
20522037 {
20532038 new ContentBlockParam(new TextBlockParam("Hello, can you tell me more about the solar system?")),
2054 }),
2039 },
20552040 },
2056 new()
2041 new AssistantMessageParam
20572042 {
2058 Role = Role.Assistant,
20592043 Content = "Certainly! The solar system is the collection of celestial bodies that orbit our Sun. It consists of eight planets, numerous moons, asteroids, comets, and other objects. The planets, in order from closest to farthest from the Sun, are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. Each planet has its own unique characteristics and features. Is there a specific aspect of the solar system you would like to know more about?"
20602044 },
2061 new()
2045 new UserMessageParam
20622046 {
2063 Role = Role.User,
2064 Content = new MessageParamContent(new List<ContentBlockParam>
2047 Content = new List<ContentBlockParam>
20652048 {
20662049 new ContentBlockParam(new TextBlockParam("Good to know.")),
20672050 new ContentBlockParam(new TextBlockParam()
from line 2052
20692052 Text = "Tell me more about Mars.",
20702053 CacheControl = new CacheControlEphemeral(),
20712054 }),
2072 })
2055 }
20732056 }
20742057 ]
20752058 };
from line 2120
21372120 "Certainly! The solar system is the collection of celestial bodies that orbit our Sun. It consists of eight planets, numerous moons, asteroids, comets, and other objects. The planets, in order from closest to farthest from the Sun, are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. Each planet has its own unique characteristics and features. Is there a specific aspect of the solar system you would like to know more about?"
21382121 )
21392122 // Second user message (with cache control)
2140 .addUserMessageOfBlockParams(
2123 .addUserMessageOfContentBlockParams(
21412124 List.of(
21422125 ContentBlockParam.ofText(TextBlockParam.builder().text("Good to know.").build()),
21432126 ContentBlockParam.ofText(
from line 2680
26972680 }),
26982681 Messages =
26992682 [
2700 new() { Role = Role.User, Content = "Can you search for information about Mars rovers?" },
2701 new()
2683 new UserMessageParam { Content = "Can you search for information about Mars rovers?" },
2684 new AssistantMessageParam
27022685 {
2703 Role = Role.Assistant,
2704 Content = new MessageParamContent(new List<ContentBlockParam>
2686 Content = new List<ContentBlockParam>
27052687 {
27062688 new ContentBlockParam(new ToolUseBlockParam()
27072689 {
from line 2694
27122694 ["query"] = JsonSerializer.SerializeToElement("Mars rovers"),
27132695 },
27142696 }),
2715 }),
2697 },
27162698 },
2717 new()
2699 new UserMessageParam
27182700 {
2719 Role = Role.User,
2720 Content = new MessageParamContent(new List<ContentBlockParam>
2701 Content = new List<ContentBlockParam>
27212702 {
27222703 new ContentBlockParam(new ToolResultBlockParam()
27232704 {
from line 2705
27242705 ToolUseID = "tool_1",
27252706 Content = "Found 3 relevant documents: Document 3 (Mars Exploration), Document 7 (Rover Technology), Document 9 (Mission History)",
27262707 }),
2727 }),
2708 },
27282709 },
2729 new()
2710 new AssistantMessageParam
27302711 {
2731 Role = Role.Assistant,
27322712 Content = "I found 3 relevant documents about Mars rovers. Let me get more details from the Mars Exploration document.",
27332713 },
2734 new()
2714 new UserMessageParam
27352715 {
2736 Role = Role.User,
2737 Content = new MessageParamContent(new List<ContentBlockParam>
2716 Content = new List<ContentBlockParam>
27382717 {
27392718 new ContentBlockParam(new TextBlockParam()
27402719 {
from line 2720
27412720 Text = "Yes, please tell me about the Perseverance rover specifically.",
27422721 CacheControl = new CacheControlEphemeral(),
27432722 }),
2744 }),
2723 },
27452724 },
27462725 ]
27472726 };
from line 2870
28912870 )
28922871 // Conversation history
28932872 .addUserMessage("Can you search for information about Mars rovers?")
2894 .addAssistantMessageOfBlockParams(
2873 .addAssistantMessageOfContentBlockParams(
28952874 List.of(
28962875 ContentBlockParam.ofToolUse(
28972876 ToolUseBlockParam.builder()
from line 2881
29022881 )
29032882 )
29042883 )
2905 .addUserMessageOfBlockParams(
2884 .addUserMessageOfContentBlockParams(
29062885 List.of(
29072886 ContentBlockParam.ofToolResult(
29082887 ToolResultBlockParam.builder()
from line 2893
29142893 )
29152894 )
29162895 )
2917 .addAssistantMessageOfBlockParams(
2896 .addAssistantMessageOfContentBlockParams(
29182897 List.of(
29192898 ContentBlockParam.ofText(
29202899 TextBlockParam.builder()
from line 2904
29252904 )
29262905 )
29272906 )
2928 .addUserMessageOfBlockParams(
2907 .addUserMessageOfContentBlockParams(
29292908 List.of(
29302909 ContentBlockParam.ofText(
29312910 TextBlockParam.builder()
build-with-claude/prompt-engineering/claude-prompting-best-practices Changed · +3 / -6 lines
from line 165
165165 Model = Model.ClaudeOpus5_5,
166166 MaxTokens = 1024,
167167 System = "You are a helpful coding assistant specializing in Python.",
168 Messages =
169 [
170 new() { Role = Role.User, Content = "How do I sort a list of dictionaries by key?" }
171 ]
168 Messages = [new UserMessageParam { Content = "How do I sort a list of dictionaries by key?" }]
172169 };
173170
174171 var message = await client.Messages.Create(parameters);
from line 668
671668 Model = Model.ClaudeSonnet4_5_20250929,
672669 MaxTokens = 16000,
673670 Thinking = new ThinkingConfigEnabled(budgetTokens: 10000),
674 Messages = [new() { Role = Role.User, Content = "..." }]
671 Messages = [new UserMessageParam { Content = "..." }]
675672 });
676673
677674 // After: adaptive thinking with effort
from line 678
681678 MaxTokens = 16000,
682679 Thinking = new ThinkingConfigAdaptive(),
683680 OutputConfig = new OutputConfig { Effort = Effort.High },
684 Messages = [new() { Role = Role.User, Content = "..." }]
681 Messages = [new UserMessageParam { Content = "..." }]
685682 });
686683 ```
687684
build-with-claude/prompt-engineering/prompting-claude-fable-5-1 Changed · +10 / -18 lines
from line 308
308308
309309 List<BetaMessageParam> messages =
310310 [
311 new() { Role = Role.User, Content = "Summarize pyproject.toml and README.md." },
311 new BetaUserMessageParam { Content = "Summarize pyproject.toml and README.md." },
312312 ];
313313
314314 BetaMessage response;
from line 323
323323 Messages = messages,
324324 });
325325 // Append the assistant turn exactly as returned, thinking blocks included.
326 messages.Add(new()
326 messages.Add(new BetaAssistantMessageParam
327327 {
328 Role = Role.Assistant,
329328 Content = response.Content.Select(block => new BetaContentBlockParam(block.Json)).ToList(),
330329 });
331330 if (response.StopReason != BetaStopReason.ToolUse)
from line 358
359358 // Send the tool results as the user turn, then a fresh copy of the nudge as a
360359 // turn-scoped system message. Leave earlier copies in place: the API clears them,
361360 // so the model sees only the newest one.
362 messages.Add(new() { Role = Role.User, Content = toolResults });
363 messages.Add(new()
361 messages.Add(new BetaUserMessageParam { Content = toolResults });
362 messages.Add(new BetaSystemMessageParam
364363 {
365 Role = Role.System,
366364 Content = BatchNudge,
367365 ClearAt = ClearAt.NextUserMessage,
368366 });
from line 489
491489 import com.anthropic.models.beta.messages.BetaMessage;
492490 import com.anthropic.models.beta.messages.BetaMessageParam;
493491 import com.anthropic.models.beta.messages.BetaStopReason;
492 import com.anthropic.models.beta.messages.BetaSystemMessageParam;
494493 import com.anthropic.models.beta.messages.BetaTool;
495494 import com.anthropic.models.beta.messages.BetaTool.InputSchema;
496495 import com.anthropic.models.beta.messages.BetaToolResultBlockParam;
from line 527
528527 .build())
529528 .build();
530529 List<BetaMessageParam> messages = new ArrayList<>();
531 messages.add(BetaMessageParam.builder()
532 .role(BetaMessageParam.Role.USER)
533 .content("Summarize pyproject.toml and README.md.")
534 .build());
530 messages.add(BetaMessageParam.ofUser("Summarize pyproject.toml and README.md."));
535531
536532 BetaMessage response;
537533 while (true) {
from line 570
574570 // Send the tool results as the user turn, then a fresh copy of the nudge as a
575571 // turn-scoped system message. Leave earlier copies in place: the API clears them,
576572 // so the model sees only the newest one.
577 messages.add(BetaMessageParam.builder()
578 .role(BetaMessageParam.Role.USER)
579 .contentOfBetaContentBlockParams(toolResults)
580 .build());
581 messages.add(BetaMessageParam.builder()
582 .role(BetaMessageParam.Role.SYSTEM)
573 messages.add(BetaMessageParam.ofUserOfContentBlockParams(toolResults));
574 messages.add(BetaMessageParam.ofSystem(BetaSystemMessageParam.builder()
583575 .content(BATCH_NUDGE)
584 .clearAt(BetaMessageParam.ClearAt.NEXT_USER_MESSAGE)
585 .build());
576 .clearAt(BetaSystemMessageParam.ClearAt.NEXT_USER_MESSAGE)
577 .build()));
586578 }
587579
588580 String finalText = response.content().stream()
build-with-claude/refusals-and-fallback Changed · +4 / -7 lines
from line 75
7575 {
7676 Model = Messages::Model.ClaudeFable5,
7777 MaxTokens = 1024,
78 Messages = [new() { Content = "Hello, Claude", Role = Role.User }],
78 Messages = [new BetaUserMessageParam { Content = "Hello, Claude" }],
7979 Fallbacks = new Default(),
8080 Betas = [AnthropicBeta.ServerSideFallback2026_07_01],
8181 }
from line 330
330330 {
331331 Model = Messages::Model.ClaudeFable5,
332332 MaxTokens = 1024,
333 Messages =
334 [
335 new() { Content = "Hello, Claude", Role = Role.User },
336 ],
333 Messages = [new BetaUserMessageParam { Content = "Hello, Claude" }],
337334 Fallbacks = new Default(),
338335 Betas = [AnthropicBeta.ServerSideFallback2026_07_01],
339336 }
from line 546
549546 {
550547 Model = Messages::Model.ClaudeFable5,
551548 MaxTokens = 1024,
552 Messages = [new() { Content = "Hello, Claude", Role = Role.User }],
549 Messages = [new BetaUserMessageParam { Content = "Hello, Claude" }],
553550 Fallbacks = new([new(Messages::Model.ClaudeOpus4_8)]),
554551 Betas = [AnthropicBeta.ServerSideFallback2026_07_01],
555552 }
from line 867
870867 {
871868 Model = Messages::Model.ClaudeFable5,
872869 MaxTokens = 1024,
873 Messages = [new() { Content = "Hello, Claude", Role = Role.User }],
870 Messages = [new BetaUserMessageParam { Content = "Hello, Claude" }],
874871 };
875872
876873 // Streaming: if the stream ends in a refusal, the handler splices the fallback