Process results programmatically changedagents-and-tools/tool-use/programmatic-tool-calling
Nearest release: v2.1.309, published 3 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+105added
Lines−104removed
From line
49
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits17to this page, all time
The whole hunk
from line 49, old and new numbered
/
from line 49
4949<CodeGroup>
5050 ```bash cURL
5151 curl https://api.anthropic.com/v1/messages \
52 -H "x-api-key: $ANTHROPIC_API_KEY" \
53 -H "anthropic-version: 2023-06-01" \
54 -H "content-type: application/json" \
55 -d '{
56 "model": "claude-opus-5-5",
57 "max_tokens": 4096,
58 "messages": [
59 {
60 "role": "user",
61 "content": "Query sales data for the West, East, and Central regions, then tell me which region had the highest revenue"
52 -H "x-api-key: $ANTHROPIC_API_KEY" \
53 -H "anthropic-version: 2023-06-01" \
54 -H "content-type: application/json" \
55 -d '{
56 "model": "claude-opus-5-5",
57 "max_tokens": 4096,
58 "messages": [
59 {
60 "role": "user",
61 "content": "Query sales data for the West, East, and Central regions, then tell me which region had the highest revenue"
62 }
63 ],
64 "tools": [
65 {
66 "type": "code_execution_20260120",
67 "name": "code_execution"
68 },
69 {
70 "name": "query_database",
71 "description": "Execute a SQL query against the sales database. Returns a list of rows as JSON objects.",
72 "input_schema": {
73 "type": "object",
74 "properties": {
75 "sql": {
76 "type": "string",
77 "description": "SQL query to execute"
6278 }
63 ],
64 "tools": [
65 {
66 "type": "code_execution_20260120",
67 "name": "code_execution"
68 },
69 {
70 "name": "query_database",
71 "description": "Execute a SQL query against the sales database. Returns a list of rows as JSON objects.",
72 "input_schema": {
73 "type": "object",
74 "properties": {
75 "sql": {
76 "type": "string",
77 "description": "SQL query to execute"
78 }
79 },
80 "required": ["sql"]
81 },
82 "allowed_callers": ["code_execution_20260120"]
83 }
84 ]
85 }'
79 },
80 "required": ["sql"]
81 },
82 "allowed_callers": ["code_execution_20260120"]
83 }
84 ]
85 }'
8686 ```
8787
8888 ```bash CLI
from line 194
194194 Model = Model.ClaudeOpus5_5,
195195 MaxTokens = 4096,
196196 Messages = [
197 new UserMessageParam {
197 new UserMessageParam
198 {
198199 Content = "Query sales data for the West, East, and Central regions, then tell me which region had the highest revenue"
199200 }
200201 ],
from line 296
295296 messages: [
296297 ['role' => 'user', 'content' => 'Query sales data for the West, East, and Central regions, then tell me which region had the highest revenue'],
297298 ],
298 model: 'claude-opus-5-5',
299 model: Model::CLAUDE_OPUS_5_5,
299300 tools: [
300301 [
301302 'type' => 'code_execution_20260120',
from line 368
367368
368369When you configure a tool to be callable from code execution and Claude determines that tool is needed:
369370
3701. Claude writes Python code that invokes the tool as a function, potentially including multiple tool calls and pre/post-processing logic.
3711. Claude writes Python code that calls the tool as a function. The code can include multiple tool calls and pre/post-processing logic.
3713722. Claude runs this code in a sandboxed container through code execution.
3723733. When a tool function is called, code execution pauses and the API returns a `tool_use` block.
3733744. You provide the tool result, and code execution continues (intermediate results are not loaded into Claude's context window).
from line 527
526527<CodeGroup>
527528 ```bash cURL
528529 curl https://api.anthropic.com/v1/messages \
529 -H "x-api-key: $ANTHROPIC_API_KEY" \
530 -H "anthropic-version: 2023-06-01" \
531 -H "content-type: application/json" \
532 -d '{
533 "model": "claude-opus-5-5",
534 "max_tokens": 4096,
535 "container": "container_xyz789",
536 "messages": [
537 {
538 "role": "user",
539 "content": "Query customer purchase history from the last quarter and identify our top 5 customers by revenue"
540 },
541 {
542 "role": "assistant",
543 "content": [
544 {
545 "type": "text",
546 "text": "I'\''ll query the purchase history and analyze the results."
547 },
548 {
549 "type": "server_tool_use",
550 "id": "srvtoolu_abc123",
551 "name": "code_execution",
552 "input": {"code": "..."}
553 },
554 {
555 "type": "tool_use",
556 "id": "toolu_def456",
557 "name": "query_database",
558 "input": {"sql": "<sql>"},
559 "caller": {
560 "type": "code_execution_20260120",
561 "tool_id": "srvtoolu_abc123"
562 }
563 }
564 ]
565 },
566 {
567 "role": "user",
568 "content": [
569 {
570 "type": "tool_result",
571 "tool_use_id": "toolu_def456",
572 "content": "[{\"customer_id\": \"C1\", \"revenue\": 45000}, {\"customer_id\": \"C2\", \"revenue\": 38000}]"
573 }
574 ]
530 -H "x-api-key: $ANTHROPIC_API_KEY" \
531 -H "anthropic-version: 2023-06-01" \
532 -H "content-type: application/json" \
533 -d '{
534 "model": "claude-opus-5-5",
535 "max_tokens": 4096,
536 "container": "container_xyz789",
537 "messages": [
538 {
539 "role": "user",
540 "content": "Query customer purchase history from the last quarter and identify our top 5 customers by revenue"
541 },
542 {
543 "role": "assistant",
544 "content": [
545 {
546 "type": "text",
547 "text": "I'\''ll query the purchase history and analyze the results."
548 },
549 {
550 "type": "server_tool_use",
551 "id": "srvtoolu_abc123",
552 "name": "code_execution",
553 "input": {"code": "..."}
554 },
555 {
556 "type": "tool_use",
557 "id": "toolu_def456",
558 "name": "query_database",
559 "input": {"sql": "<sql>"},
560 "caller": {
561 "type": "code_execution_20260120",
562 "tool_id": "srvtoolu_abc123"
575563 }
576 ],
577 "tools": [
578 {
579 "type": "code_execution_20260120",
580 "name": "code_execution"
581 },
582 {
583 "name": "query_database",
584 "description": "Execute a SQL query against the sales database. Returns a list of rows as JSON objects.",
585 "input_schema": {
586 "type": "object",
587 "properties": {
588 "sql": {
589 "type": "string",
590 "description": "SQL query to execute"
591 }
592 },
593 "required": ["sql"]
594 },
595 "allowed_callers": ["code_execution_20260120"]
596 }
564 }
597565 ]
598 }'
566 },
567 {
568 "role": "user",
569 "content": [
570 {
571 "type": "tool_result",
572 "tool_use_id": "toolu_def456",
573 "content": "[{\"customer_id\": \"C1\", \"revenue\": 45000}, {\"customer_id\": \"C2\", \"revenue\": 38000}]"
574 }
575 ]
576 }
577 ],
578 "tools": [
579 {
580 "type": "code_execution_20260120",
581 "name": "code_execution"
582 },
583 {
584 "name": "query_database",
585 "description": "Execute a SQL query against the sales database. Returns a list of rows as JSON objects.",
586 "input_schema": {
587 "type": "object",
588 "properties": {
589 "sql": {
590 "type": "string",
591 "description": "SQL query to execute"
592 }
593 },
594 "required": ["sql"]
595 },
596 "allowed_callers": ["code_execution_20260120"]
597 }
598 ]
599 }'
599600 ```
600601
601602 ```bash CLI
No line in this hunk matches that.