mirror of
https://github.com/anthropics/skills
synced 2026-07-05 11:36:53 +00:00
Add Opus 4.8 migration guide and model updates to claude-api skill (#1216)
* Add Managed Agents self-hosted sandboxes + mid-session agent updates + MCP tool-output offload to claude-api skill
Self-hosted sandboxes: new shared/managed-agents-self-hosted-sandboxes.md for config:{type:"self_hosted"} — agent loop on Anthropic's orchestration, tool execution on customer infra via outbound-polling worker. Covers EnvironmentWorker.run()/.run_one() (Py/TS), ant beta:worker poll/run, mid-level work.poller()/WorkPoller (Py/TS/Go only; Go has no auto_stop opt-out), AgentToolContext/beta_agent_toolset/tool_runner(), monitoring (environments.work.stats/stop — x-api-key, call from outside worker host), runtime deps, cloud-vs-self_hosted delta table, credentials, security ownership split. Cross-refs in environments.md, overview.md (Reading Guide + rewrote cloud-only pitfall), api-reference.md (SDK row + naming-quirks + schema + work REST rows), tools.md (Who-runs-it carve-out), onboarding.md, live-sources.md.
Mid-session agent updates: sessions.update(session_id, agent={tools, mcp_servers}, vault_ids=[...]) — session-local override (doesn't bump agent version), full-replacement semantics, session must be idle. New core.md section + pointers in tools.md, api-reference.md (UpdateSession row), overview.md.
Large MCP tool outputs → files: >100K tokens → automatic offload to sandbox file; agent gets truncated preview + path. Plus: invalid vault credentials don't block sessions.create() — session.error event fires, auth retries on next idle→running. Both in tools.md.
* Point ant CLI install ref to live-sources.md (OSS has no anthropic-cli.md)
* Add Opus 4.8 model migration guide to claude-api skill
* Add prescriptive tool-description guidance for Opus 4.8 to claude-api skill
This commit is contained in:
@@ -27,7 +27,7 @@ Never mix the two — don't reach for `requests`/`fetch` in a Python or TypeScri
|
|||||||
|
|
||||||
Unless the user requests otherwise:
|
Unless the user requests otherwise:
|
||||||
|
|
||||||
For the Claude model version, please use Claude Opus 4.7, which you can access via the exact model string `claude-opus-4-7`. Please default to using adaptive thinking (`thinking: {type: "adaptive"}`) for anything remotely complicated. And finally, please default to streaming for any request that may involve long input, long output, or high `max_tokens` — it prevents hitting request timeouts. Use the SDK's `.get_final_message()` / `.finalMessage()` helper to get the complete response if you don't need to handle individual stream events
|
For the Claude model version, please use Claude Opus 4.8, which you can access via the exact model string `claude-opus-4-8`. Please default to using adaptive thinking (`thinking: {type: "adaptive"}`) for anything remotely complicated. And finally, please default to streaming for any request that may involve long input, long output, or high `max_tokens` — it prevents hitting request timeouts. Use the SDK's `.get_final_message()` / `.finalMessage()` helper to get the complete response if you don't need to handle individual stream events
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -161,16 +161,17 @@ Everything goes through `POST /v1/messages`. Tools and output constraints are fe
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Current Models (cached: 2026-04-15)
|
## Current Models (cached: 2026-05-26)
|
||||||
|
|
||||||
| Model | Model ID | Context | Input $/1M | Output $/1M |
|
| Model | Model ID | Context | Input $/1M | Output $/1M |
|
||||||
| ----------------- | ------------------- | -------------- | ---------- | ----------- |
|
| ----------------- | ------------------- | -------------- | ---------- | ----------- |
|
||||||
|
| Claude Opus 4.8 | `claude-opus-4-8` | 1M | $5.00 | $25.00 |
|
||||||
| Claude Opus 4.7 | `claude-opus-4-7` | 1M | $5.00 | $25.00 |
|
| Claude Opus 4.7 | `claude-opus-4-7` | 1M | $5.00 | $25.00 |
|
||||||
| Claude Opus 4.6 | `claude-opus-4-6` | 1M | $5.00 | $25.00 |
|
| Claude Opus 4.6 | `claude-opus-4-6` | 1M | $5.00 | $25.00 |
|
||||||
| Claude Sonnet 4.6 | `claude-sonnet-4-6` | 1M | $3.00 | $15.00 |
|
| Claude Sonnet 4.6 | `claude-sonnet-4-6` | 1M | $3.00 | $15.00 |
|
||||||
| Claude Haiku 4.5 | `claude-haiku-4-5` | 200K | $1.00 | $5.00 |
|
| Claude Haiku 4.5 | `claude-haiku-4-5` | 200K | $1.00 | $5.00 |
|
||||||
|
|
||||||
**ALWAYS use `claude-opus-4-7` unless the user explicitly names a different model.** This is non-negotiable. Do not use `claude-sonnet-4-6`, `claude-sonnet-4-5`, or any other model unless the user literally says "use sonnet" or "use haiku". Never downgrade for cost — that's the user's decision, not yours.
|
**ALWAYS use `claude-opus-4-8` unless the user explicitly names a different model.** This is non-negotiable. Do not use `claude-sonnet-4-6`, `claude-sonnet-4-5`, or any other model unless the user literally says "use sonnet" or "use haiku". Never downgrade for cost — that's the user's decision, not yours.
|
||||||
|
|
||||||
**CRITICAL: Use only the exact model ID strings from the table above — they are complete as-is. Do not append date suffixes.** For example, use `claude-sonnet-4-5`, never `claude-sonnet-4-5-20250514` or any other date-suffixed variant you might recall from training data. If the user requests an older model not in the table (e.g., "opus 4.5", "sonnet 3.7"), read `shared/models.md` for the exact ID — do not construct one yourself.
|
**CRITICAL: Use only the exact model ID strings from the table above — they are complete as-is. Do not append date suffixes.** For example, use `claude-sonnet-4-5`, never `claude-sonnet-4-5-20250514` or any other date-suffixed variant you might recall from training data. If the user requests an older model not in the table (e.g., "opus 4.5", "sonnet 3.7"), read `shared/models.md` for the exact ID — do not construct one yourself.
|
||||||
|
|
||||||
@@ -182,23 +183,23 @@ A note: if any of the model strings above look unfamiliar to you, that's to be e
|
|||||||
|
|
||||||
## Thinking & Effort (Quick Reference)
|
## Thinking & Effort (Quick Reference)
|
||||||
|
|
||||||
**Opus 4.7 — Adaptive thinking only:** Use `thinking: {type: "adaptive"}`. `thinking: {type: "enabled", budget_tokens: N}` returns a 400 on Opus 4.7 — adaptive is the only on-mode. `{type: "disabled"}` and omitting `thinking` both work. Sampling parameters (`temperature`, `top_p`, `top_k`) are also removed and will 400. See `shared/model-migration.md` → Migrating to Opus 4.7 for the full breaking-change list.
|
**Opus 4.8 / 4.7 — Adaptive thinking only:** Use `thinking: {type: "adaptive"}`. `thinking: {type: "enabled", budget_tokens: N}` returns a 400 — adaptive is the only on-mode. `{type: "disabled"}` and omitting `thinking` both work. Sampling parameters (`temperature`, `top_p`, `top_k`) are also removed and will 400. Opus 4.8 keeps the same request surface as 4.7 (no new breaking changes) — see `shared/model-migration.md` → Migrating to Opus 4.8 for the behavioral re-tuning, and → Migrating to Opus 4.7 for the full breaking-change list when coming from 4.6 or earlier. Note: with `thinking` disabled, Opus 4.8 may write longer reasoning into the visible response — leave adaptive thinking on, or add a final-answer-only instruction (see the migration guide).
|
||||||
**Opus 4.6 — Adaptive thinking (recommended):** Use `thinking: {type: "adaptive"}`. Claude dynamically decides when and how much to think. No `budget_tokens` needed — `budget_tokens` is deprecated on Opus 4.6 and Sonnet 4.6 and should not be used for new code. Adaptive thinking also automatically enables interleaved thinking (no beta header needed). **When the user asks for "extended thinking", a "thinking budget", or `budget_tokens`: always use Opus 4.7 or 4.6 with `thinking: {type: "adaptive"}`. The concept of a fixed token budget for thinking is deprecated — adaptive thinking replaces it. Do NOT use `budget_tokens` for new 4.6/4.7 code and do NOT switch to an older model.** *Gradual-migration carve-out:* `budget_tokens` is still functional on Opus 4.6 and Sonnet 4.6 as a transitional escape hatch — if you're migrating existing code and need a hard token ceiling before you've tuned `effort`, see `shared/model-migration.md` → Transitional escape hatch. Note: this carve-out does **not** apply to Opus 4.7 — `budget_tokens` is fully removed there.
|
**Opus 4.6 — Adaptive thinking (recommended):** Use `thinking: {type: "adaptive"}`. Claude dynamically decides when and how much to think. No `budget_tokens` needed — `budget_tokens` is deprecated on Opus 4.6 and Sonnet 4.6 and should not be used for new code. Adaptive thinking also automatically enables interleaved thinking (no beta header needed). **When the user asks for "extended thinking", a "thinking budget", or `budget_tokens`: always use Opus 4.8, 4.7, or 4.6 with `thinking: {type: "adaptive"}`. The concept of a fixed token budget for thinking is deprecated — adaptive thinking replaces it. Do NOT use `budget_tokens` for new 4.6/4.7/4.8 code and do NOT switch to an older model.** *Gradual-migration carve-out:* `budget_tokens` is still functional on Opus 4.6 and Sonnet 4.6 as a transitional escape hatch — if you're migrating existing code and need a hard token ceiling before you've tuned `effort`, see `shared/model-migration.md` → Transitional escape hatch. Note: this carve-out does **not** apply to Opus 4.7 or 4.8 — `budget_tokens` is fully removed there.
|
||||||
**Effort parameter (GA, no beta header):** Controls thinking depth and overall token spend via `output_config: {effort: "low"|"medium"|"high"|"max"}` (inside `output_config`, not top-level). Default is `high` (equivalent to omitting it). `max` is Opus-tier only (Opus 4.6 and later — not Sonnet or Haiku). Opus 4.7 adds `"xhigh"` (between `high` and `max`) — the best setting for most coding and agentic use cases on 4.7, and the default in Claude Code; use a minimum of `high` for most intelligence-sensitive work. Works on Opus 4.5, Opus 4.6, Opus 4.7, and Sonnet 4.6. Will error on Sonnet 4.5 / Haiku 4.5. On Opus 4.7, effort matters more than on any prior Opus — re-tune it when migrating. Combine with adaptive thinking for the best cost-quality tradeoffs. Lower effort means fewer and more-consolidated tool calls, less preamble, and terser confirmations — `high` is often the sweet spot balancing quality and token efficiency; use `max` when correctness matters more than cost; use `low` for subagents or simple tasks.
|
**Effort parameter (GA, no beta header):** Controls thinking depth and overall token spend via `output_config: {effort: "low"|"medium"|"high"|"max"}` (inside `output_config`, not top-level). Default is `high` (equivalent to omitting it). `max` is Opus-tier only (Opus 4.6 and later — not Sonnet or Haiku). Opus 4.7 added `"xhigh"` (between `high` and `max`) — the best setting for most coding and agentic use cases on Opus 4.7/4.8, and the default in Claude Code; use a minimum of `high` for most intelligence-sensitive work. Works on Opus 4.5, Opus 4.6, Opus 4.7, Opus 4.8, and Sonnet 4.6. Will error on Sonnet 4.5 / Haiku 4.5. On Opus 4.7 and 4.8, effort matters more than on any prior Opus — re-tune it when migrating, and run long-horizon/agentic tasks at `high`/`xhigh` with the full task spec given up front. Combine with adaptive thinking for the best cost-quality tradeoffs. Lower effort means fewer and more-consolidated tool calls, less preamble, and terser confirmations — `high` is often the sweet spot balancing quality and token efficiency; use `max` when correctness matters more than cost; use `low` for subagents or simple tasks.
|
||||||
|
|
||||||
**Opus 4.7 — thinking content omitted by default:** `thinking` blocks still stream but their text is empty unless you opt in with `thinking: {type: "adaptive", display: "summarized"}` (default is `"omitted"`). Silent change — no error. If you stream reasoning to users, the default looks like a long pause before output; set `"summarized"` to restore visible progress.
|
**Opus 4.8 / 4.7 — thinking content omitted by default:** `thinking` blocks still stream but their text is empty unless you opt in with `thinking: {type: "adaptive", display: "summarized"}` (default is `"omitted"`). Silent change — no error. If you stream reasoning to users, the default looks like a long pause before output; set `"summarized"` to restore visible progress.
|
||||||
|
|
||||||
**Task Budgets (beta, Opus 4.7):** `output_config: {task_budget: {type: "tokens", total: N}}` tells the model how many tokens it has for a full agentic loop — it sees a running countdown and self-moderates (minimum 20,000; beta header `task-budgets-2026-03-13`). Distinct from `max_tokens`, which is an enforced per-response ceiling the model is not aware of. See `shared/model-migration.md` → Task Budgets.
|
**Task Budgets (beta, Opus 4.7 / 4.8):** `output_config: {task_budget: {type: "tokens", total: N}}` tells the model how many tokens it has for a full agentic loop — it sees a running countdown and self-moderates (minimum 20,000; beta header `task-budgets-2026-03-13`). Distinct from `max_tokens`, which is an enforced per-response ceiling the model is not aware of. See `shared/model-migration.md` → Task Budgets.
|
||||||
|
|
||||||
**Sonnet 4.6:** Supports adaptive thinking (`thinking: {type: "adaptive"}`). `budget_tokens` is deprecated on Sonnet 4.6 — use adaptive thinking instead.
|
**Sonnet 4.6:** Supports adaptive thinking (`thinking: {type: "adaptive"}`). `budget_tokens` is deprecated on Sonnet 4.6 — use adaptive thinking instead.
|
||||||
|
|
||||||
**Older models (only if explicitly requested):** If the user specifically asks for Sonnet 4.5 or another older model, use `thinking: {type: "enabled", budget_tokens: N}`. `budget_tokens` must be less than `max_tokens` (minimum 1024). Never choose an older model just because the user mentions `budget_tokens` — use Opus 4.7 with adaptive thinking instead.
|
**Older models (only if explicitly requested):** If the user specifically asks for Sonnet 4.5 or another older model, use `thinking: {type: "enabled", budget_tokens: N}`. `budget_tokens` must be less than `max_tokens` (minimum 1024). Never choose an older model just because the user mentions `budget_tokens` — use Opus 4.8 with adaptive thinking instead.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Compaction (Quick Reference)
|
## Compaction (Quick Reference)
|
||||||
|
|
||||||
**Beta, Opus 4.7, Opus 4.6, and Sonnet 4.6.** For long-running conversations that may exceed the 1M context window, enable server-side compaction. The API automatically summarizes earlier context when it approaches the trigger threshold (default: 150K tokens). Requires beta header `compact-2026-01-12`.
|
**Beta, Opus 4.8, Opus 4.7, Opus 4.6, and Sonnet 4.6.** For long-running conversations that may exceed the 1M context window, enable server-side compaction. The API automatically summarizes earlier context when it approaches the trigger threshold (default: 150K tokens). Requires beta header `compact-2026-01-12`.
|
||||||
|
|
||||||
**Critical:** Append `response.content` (not just the text) back to your messages on every turn. Compaction blocks in the response must be preserved — the API uses them to replace the compacted history on the next request. Extracting only the text string and appending that will silently lose the compaction state.
|
**Critical:** Append `response.content` (not just the text) back to your messages on every turn. Compaction blocks in the response must be preserved — the API uses them to replace the compacted history on the next request. Extracting only the text string and appending that will silently lose the compaction state.
|
||||||
|
|
||||||
@@ -256,7 +257,7 @@ After detecting the language, read the relevant files based on what the user nee
|
|||||||
|
|
||||||
**Long-running conversations (may exceed context window):**
|
**Long-running conversations (may exceed context window):**
|
||||||
→ Read `{lang}/claude-api/README.md` — see Compaction section
|
→ Read `{lang}/claude-api/README.md` — see Compaction section
|
||||||
**Migrating to a newer model (Opus 4.7 / Opus 4.6 / Sonnet 4.6) or replacing a retired model:**
|
**Migrating to a newer model (Opus 4.8 / Opus 4.7 / Opus 4.6 / Sonnet 4.6) or replacing a retired model:**
|
||||||
→ Read `shared/model-migration.md`
|
→ Read `shared/model-migration.md`
|
||||||
**Prompt caching / optimize caching / "why is my cache hit rate low":**
|
**Prompt caching / optimize caching / "why is my cache hit rate low":**
|
||||||
→ Read `shared/prompt-caching.md` + `{lang}/claude-api/README.md` (Prompt Caching section)
|
→ Read `shared/prompt-caching.md` + `{lang}/claude-api/README.md` (Prompt Caching section)
|
||||||
@@ -311,13 +312,13 @@ Live documentation URLs are in `shared/live-sources.md`.
|
|||||||
## Common Pitfalls
|
## Common Pitfalls
|
||||||
|
|
||||||
- Don't truncate inputs when passing files or content to the API. If the content is too long to fit in the context window, notify the user and discuss options (chunking, summarization, etc.) rather than silently truncating.
|
- Don't truncate inputs when passing files or content to the API. If the content is too long to fit in the context window, notify the user and discuss options (chunking, summarization, etc.) rather than silently truncating.
|
||||||
- **Opus 4.7 thinking:** Adaptive only. `thinking: {type: "enabled", budget_tokens: N}` returns 400 on Opus 4.7 — `budget_tokens` is fully removed there (along with `temperature`, `top_p`, `top_k`). Use `thinking: {type: "adaptive"}`.
|
- **Opus 4.8 / 4.7 thinking:** Adaptive only. `thinking: {type: "enabled", budget_tokens: N}` returns 400 — `budget_tokens` is fully removed (along with `temperature`, `top_p`, `top_k`). Use `thinking: {type: "adaptive"}`. Opus 4.8 inherits this surface from 4.7 with no new breaking changes.
|
||||||
- **Opus 4.6 / Sonnet 4.6 thinking:** Use `thinking: {type: "adaptive"}` — do NOT use `budget_tokens` for new 4.6 code (deprecated on both Opus 4.6 and Sonnet 4.6; for gradual migration of existing code, see the transitional escape hatch in `shared/model-migration.md` — note this carve-out does not apply to Opus 4.7). For older models, `budget_tokens` must be less than `max_tokens` (minimum 1024). This will throw an error if you get it wrong.
|
- **Opus 4.6 / Sonnet 4.6 thinking:** Use `thinking: {type: "adaptive"}` — do NOT use `budget_tokens` for new 4.6 code (deprecated on both Opus 4.6 and Sonnet 4.6; for gradual migration of existing code, see the transitional escape hatch in `shared/model-migration.md` — note this carve-out does not apply to Opus 4.7 or 4.8). For older models, `budget_tokens` must be less than `max_tokens` (minimum 1024). This will throw an error if you get it wrong.
|
||||||
- **4.6/4.7 family prefill removed:** Assistant message prefills (last-assistant-turn prefills) return a 400 error on Opus 4.6, Opus 4.7, and Sonnet 4.6. Use structured outputs (`output_config.format`) or system prompt instructions to control response format instead.
|
- **4.6/4.7/4.8 family prefill removed:** Assistant message prefills (last-assistant-turn prefills) return a 400 error on Opus 4.6, Opus 4.7, Opus 4.8, and Sonnet 4.6. Use structured outputs (`output_config.format`) or system prompt instructions to control response format instead.
|
||||||
- **Confirm migration scope before editing:** When a user asks to migrate code to a newer Claude model without naming a specific file, directory, or file list, **ask which scope to apply first** — the entire working directory, a specific subdirectory, or a specific set of files. Do not start editing until the user confirms. Imperative phrasings like "migrate my codebase", "move my project to X", "upgrade to Sonnet 4.6", or bare "migrate to Opus 4.7" are **still ambiguous** — they tell you what to do but not where, so ask. Proceed without asking only when the prompt names an exact file, a specific directory, or an explicit file list ("migrate `app.py`", "migrate everything under `services/`", "update `a.py` and `b.py`"). See `shared/model-migration.md` Step 0.
|
- **Confirm migration scope before editing:** When a user asks to migrate code to a newer Claude model without naming a specific file, directory, or file list, **ask which scope to apply first** — the entire working directory, a specific subdirectory, or a specific set of files. Do not start editing until the user confirms. Imperative phrasings like "migrate my codebase", "move my project to X", "upgrade to Sonnet 4.6", or bare "migrate to Opus 4.8" are **still ambiguous** — they tell you what to do but not where, so ask. Proceed without asking only when the prompt names an exact file, a specific directory, or an explicit file list ("migrate `app.py`", "migrate everything under `services/`", "update `a.py` and `b.py`"). See `shared/model-migration.md` Step 0.
|
||||||
- **`max_tokens` defaults:** Don't lowball `max_tokens` — hitting the cap truncates output mid-thought and requires a retry. For non-streaming requests, default to `~16000` (keeps responses under SDK HTTP timeouts). For streaming requests, default to `~64000` (timeouts aren't a concern, so give the model room). Only go lower when you have a hard reason: classification (`~256`), cost caps, or deliberately short outputs.
|
- **`max_tokens` defaults:** Don't lowball `max_tokens` — hitting the cap truncates output mid-thought and requires a retry. For non-streaming requests, default to `~16000` (keeps responses under SDK HTTP timeouts). For streaming requests, default to `~64000` (timeouts aren't a concern, so give the model room). Only go lower when you have a hard reason: classification (`~256`), cost caps, or deliberately short outputs.
|
||||||
- **128K output tokens:** Opus 4.6 and Opus 4.7 support up to 128K `max_tokens`, but the SDKs require streaming for values that large to avoid HTTP timeouts. Use `.stream()` with `.get_final_message()` / `.finalMessage()`.
|
- **128K output tokens:** Opus 4.6, Opus 4.7, and Opus 4.8 support up to 128K `max_tokens`, but the SDKs require streaming for values that large to avoid HTTP timeouts. Use `.stream()` with `.get_final_message()` / `.finalMessage()`.
|
||||||
- **Tool call JSON parsing (4.6/4.7 family):** Opus 4.6, Opus 4.7, and Sonnet 4.6 may produce different JSON string escaping in tool call `input` fields (e.g., Unicode or forward-slash escaping). Always parse tool inputs with `json.loads()` / `JSON.parse()` — never do raw string matching on the serialized input.
|
- **Tool call JSON parsing (4.6/4.7/4.8 family):** Opus 4.6, Opus 4.7, Opus 4.8, and Sonnet 4.6 may produce different JSON string escaping in tool call `input` fields (e.g., Unicode or forward-slash escaping). Always parse tool inputs with `json.loads()` / `JSON.parse()` — never do raw string matching on the serialized input.
|
||||||
- **Structured outputs (all models):** Use `output_config: {format: {...}}` instead of the deprecated `output_format` parameter on `messages.create()`. This is a general API change, not 4.6-specific.
|
- **Structured outputs (all models):** Use `output_config: {format: {...}}` instead of the deprecated `output_format` parameter on `messages.create()`. This is a general API change, not 4.6-specific.
|
||||||
- **Don't reimplement SDK functionality:** The SDK provides high-level helpers — use them instead of building from scratch. Specifically: use `stream.finalMessage()` instead of wrapping `.on()` events in `new Promise()`; use typed exception classes (`Anthropic.RateLimitError`, etc.) instead of string-matching error messages; use SDK types (`Anthropic.MessageParam`, `Anthropic.Tool`, `Anthropic.Message`, etc.) instead of redefining equivalent interfaces.
|
- **Don't reimplement SDK functionality:** The SDK provides high-level helpers — use them instead of building from scratch. Specifically: use `stream.finalMessage()` instead of wrapping `.on()` events in `new Promise()`; use typed exception classes (`Anthropic.RateLimitError`, etc.) instead of string-matching error messages; use SDK types (`Anthropic.MessageParam`, `Anthropic.Tool`, `Anthropic.Message`, etc.) instead of redefining equivalent interfaces.
|
||||||
- **Don't define custom types for SDK data structures:** The SDK exports types for all API objects. Use `Anthropic.MessageParam` for messages, `Anthropic.Tool` for tool definitions, `Anthropic.ToolUseBlock` / `Anthropic.ToolResultBlockParam` for tool results, `Anthropic.Message` for responses. Defining your own `interface ChatMessage { role: string; content: unknown }` duplicates what the SDK already provides and loses type safety.
|
- **Don't define custom types for SDK data structures:** The SDK exports types for all API objects. Use `Anthropic.MessageParam` for messages, `Anthropic.Tool` for tool definitions, `Anthropic.ToolUseBlock` / `Anthropic.ToolResultBlockParam` for tool results, `Anthropic.Message` for responses. Defining your own `interface ChatMessage { role: string; content: unknown }` duplicates what the SDK already provides and loses type safety.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ curl https://api.anthropic.com/v1/messages \
|
|||||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||||
-H "anthropic-version: 2023-06-01" \
|
-H "anthropic-version: 2023-06-01" \
|
||||||
-d '{
|
-d '{
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"max_tokens": 16000,
|
"max_tokens": 16000,
|
||||||
"messages": [
|
"messages": [
|
||||||
{"role": "user", "content": "What is the capital of France?"}
|
{"role": "user", "content": "What is the capital of France?"}
|
||||||
@@ -38,7 +38,7 @@ response=$(curl -s https://api.anthropic.com/v1/messages \
|
|||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||||
-H "anthropic-version: 2023-06-01" \
|
-H "anthropic-version: 2023-06-01" \
|
||||||
-d '{"model":"claude-opus-4-7","max_tokens":16000,"messages":[{"role":"user","content":"Hello"}]}')
|
-d '{"model":"claude-opus-4-8","max_tokens":16000,"messages":[{"role":"user","content":"Hello"}]}')
|
||||||
|
|
||||||
# Print the first text block (-r strips the JSON quotes)
|
# Print the first text block (-r strips the JSON quotes)
|
||||||
echo "$response" | jq -r '.content[0].text'
|
echo "$response" | jq -r '.content[0].text'
|
||||||
@@ -65,7 +65,7 @@ curl https://api.anthropic.com/v1/messages \
|
|||||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||||
-H "anthropic-version: 2023-06-01" \
|
-H "anthropic-version: 2023-06-01" \
|
||||||
-d '{
|
-d '{
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"max_tokens": 64000,
|
"max_tokens": 64000,
|
||||||
"stream": true,
|
"stream": true,
|
||||||
"messages": [{"role": "user", "content": "Write a haiku"}]
|
"messages": [{"role": "user", "content": "Write a haiku"}]
|
||||||
@@ -104,7 +104,7 @@ curl https://api.anthropic.com/v1/messages \
|
|||||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||||
-H "anthropic-version: 2023-06-01" \
|
-H "anthropic-version: 2023-06-01" \
|
||||||
-d '{
|
-d '{
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"max_tokens": 16000,
|
"max_tokens": 16000,
|
||||||
"tools": [{
|
"tools": [{
|
||||||
"name": "get_weather",
|
"name": "get_weather",
|
||||||
@@ -129,7 +129,7 @@ curl https://api.anthropic.com/v1/messages \
|
|||||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||||
-H "anthropic-version: 2023-06-01" \
|
-H "anthropic-version: 2023-06-01" \
|
||||||
-d '{
|
-d '{
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"max_tokens": 16000,
|
"max_tokens": 16000,
|
||||||
"tools": [{
|
"tools": [{
|
||||||
"name": "get_weather",
|
"name": "get_weather",
|
||||||
@@ -167,7 +167,7 @@ curl https://api.anthropic.com/v1/messages \
|
|||||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||||
-H "anthropic-version: 2023-06-01" \
|
-H "anthropic-version: 2023-06-01" \
|
||||||
-d '{
|
-d '{
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"max_tokens": 16000,
|
"max_tokens": 16000,
|
||||||
"system": [
|
"system": [
|
||||||
{"type": "text", "text": "<large shared prompt...>", "cache_control": {"type": "ephemeral"}}
|
{"type": "text", "text": "<large shared prompt...>", "cache_control": {"type": "ephemeral"}}
|
||||||
@@ -182,17 +182,17 @@ For 1-hour TTL: `"cache_control": {"type": "ephemeral", "ttl": "1h"}`. Top-level
|
|||||||
|
|
||||||
## Extended Thinking
|
## Extended Thinking
|
||||||
|
|
||||||
> **Opus 4.7, Opus 4.6, and Sonnet 4.6:** Use adaptive thinking. `budget_tokens` is removed on Opus 4.7 (400 if sent); deprecated on Opus 4.6 and Sonnet 4.6.
|
> **Opus 4.8, Opus 4.7, Opus 4.6, and Sonnet 4.6:** Use adaptive thinking. `budget_tokens` is removed on Opus 4.8 and 4.7 (400 if sent); deprecated on Opus 4.6 and Sonnet 4.6.
|
||||||
> **Older models:** Use `"type": "enabled"` with `"budget_tokens": N` (must be < `max_tokens`, min 1024).
|
> **Older models:** Use `"type": "enabled"` with `"budget_tokens": N` (must be < `max_tokens`, min 1024).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Opus 4.7 / 4.6: adaptive thinking (recommended)
|
# Opus 4.8 / 4.7 / 4.6: adaptive thinking (recommended)
|
||||||
curl https://api.anthropic.com/v1/messages \
|
curl https://api.anthropic.com/v1/messages \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||||
-H "anthropic-version: 2023-06-01" \
|
-H "anthropic-version: 2023-06-01" \
|
||||||
-d '{
|
-d '{
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"max_tokens": 16000,
|
"max_tokens": 16000,
|
||||||
"thinking": {
|
"thinking": {
|
||||||
"type": "adaptive"
|
"type": "adaptive"
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ curl -X POST https://api.anthropic.com/v1/agents \
|
|||||||
"${HEADERS[@]}" \
|
"${HEADERS[@]}" \
|
||||||
-d '{
|
-d '{
|
||||||
"name": "Coding Assistant",
|
"name": "Coding Assistant",
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"tools": [{ "type": "agent_toolset_20260401" }]
|
"tools": [{ "type": "agent_toolset_20260401" }]
|
||||||
}'
|
}'
|
||||||
# → { "id": "agent_abc123", ... }
|
# → { "id": "agent_abc123", ... }
|
||||||
@@ -85,7 +85,7 @@ curl -X POST https://api.anthropic.com/v1/agents \
|
|||||||
"${HEADERS[@]}" \
|
"${HEADERS[@]}" \
|
||||||
-d '{
|
-d '{
|
||||||
"name": "Code Reviewer",
|
"name": "Code Reviewer",
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"system": "You are a senior code reviewer. Be thorough and constructive.",
|
"system": "You are a senior code reviewer. Be thorough and constructive.",
|
||||||
"tools": [
|
"tools": [
|
||||||
{ "type": "agent_toolset_20260401" },
|
{ "type": "agent_toolset_20260401" },
|
||||||
@@ -291,7 +291,7 @@ curl -X POST https://api.anthropic.com/v1/agents \
|
|||||||
"${HEADERS[@]}" \
|
"${HEADERS[@]}" \
|
||||||
-d '{
|
-d '{
|
||||||
"name": "MCP Agent",
|
"name": "MCP Agent",
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"mcp_servers": [
|
"mcp_servers": [
|
||||||
{ "type": "url", "name": "my-tools", "url": "https://my-mcp-server.example.com/sse" }
|
{ "type": "url", "name": "my-tools", "url": "https://my-mcp-server.example.com/sse" }
|
||||||
],
|
],
|
||||||
@@ -322,7 +322,7 @@ curl -X POST https://api.anthropic.com/v1/agents \
|
|||||||
"${HEADERS[@]}" \
|
"${HEADERS[@]}" \
|
||||||
-d '{
|
-d '{
|
||||||
"name": "Restricted Agent",
|
"name": "Restricted Agent",
|
||||||
"model": "claude-opus-4-7",
|
"model": "claude-opus-4-8",
|
||||||
"tools": [
|
"tools": [
|
||||||
{
|
{
|
||||||
"type": "agent_toolset_20260401",
|
"type": "agent_toolset_20260401",
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ fmt.Println(environment.ID) // env_...
|
|||||||
agent, err := client.Beta.Agents.New(ctx, anthropic.BetaAgentNewParams{
|
agent, err := client.Beta.Agents.New(ctx, anthropic.BetaAgentNewParams{
|
||||||
Name: "Coding Assistant",
|
Name: "Coding Assistant",
|
||||||
Model: anthropic.BetaManagedAgentsModelConfigParams{
|
Model: anthropic.BetaManagedAgentsModelConfigParams{
|
||||||
ID: "claude-opus-4-7",
|
ID: "claude-opus-4-8",
|
||||||
Type: anthropic.BetaManagedAgentsModelConfigParamsTypeModelConfig,
|
Type: anthropic.BetaManagedAgentsModelConfigParamsTypeModelConfig,
|
||||||
},
|
},
|
||||||
System: anthropic.String("You are a helpful coding assistant."),
|
System: anthropic.String("You are a helpful coding assistant."),
|
||||||
@@ -380,7 +380,7 @@ if err != nil {
|
|||||||
agent, err := client.Beta.Agents.New(ctx, anthropic.BetaAgentNewParams{
|
agent, err := client.Beta.Agents.New(ctx, anthropic.BetaAgentNewParams{
|
||||||
Name: "GitHub Assistant",
|
Name: "GitHub Assistant",
|
||||||
Model: anthropic.BetaManagedAgentsModelConfigParams{
|
Model: anthropic.BetaManagedAgentsModelConfigParams{
|
||||||
ID: "claude-opus-4-7",
|
ID: "claude-opus-4-8",
|
||||||
Type: anthropic.BetaManagedAgentsModelConfigParamsTypeModelConfig,
|
Type: anthropic.BetaManagedAgentsModelConfigParamsTypeModelConfig,
|
||||||
},
|
},
|
||||||
MCPServers: []anthropic.BetaManagedAgentsUrlmcpServerParams{{
|
MCPServers: []anthropic.BetaManagedAgentsUrlmcpServerParams{{
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ static class GetWeather implements Supplier<String> {
|
|||||||
|
|
||||||
BetaToolRunner toolRunner = client.beta().messages().toolRunner(
|
BetaToolRunner toolRunner = client.beta().messages().toolRunner(
|
||||||
MessageCreateParams.builder()
|
MessageCreateParams.builder()
|
||||||
.model("claude-opus-4-7")
|
.model("claude-opus-4-8")
|
||||||
.maxTokens(16000L)
|
.maxTokens(16000L)
|
||||||
.putAdditionalHeader("anthropic-beta", "structured-outputs-2025-11-13")
|
.putAdditionalHeader("anthropic-beta", "structured-outputs-2025-11-13")
|
||||||
.addTool(GetWeather.class)
|
.addTool(GetWeather.class)
|
||||||
@@ -164,7 +164,7 @@ import com.anthropic.models.beta.messages.ToolRunnerCreateParams;
|
|||||||
BetaMemoryToolHandler memoryHandler = new FileSystemMemoryToolHandler(sandboxRoot);
|
BetaMemoryToolHandler memoryHandler = new FileSystemMemoryToolHandler(sandboxRoot);
|
||||||
|
|
||||||
MessageCreateParams createParams = MessageCreateParams.builder()
|
MessageCreateParams createParams = MessageCreateParams.builder()
|
||||||
.model("claude-opus-4-7")
|
.model("claude-opus-4-8")
|
||||||
.maxTokens(4096L)
|
.maxTokens(4096L)
|
||||||
.addTool(BetaMemoryTool20250818.builder().build())
|
.addTool(BetaMemoryTool20250818.builder().build())
|
||||||
.addUserMessage("Remember that my favorite color is blue")
|
.addUserMessage("Remember that my favorite color is blue")
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ import com.anthropic.models.beta.sessions.SessionCreateParams;
|
|||||||
// 1. Create the agent (reusable, versioned)
|
// 1. Create the agent (reusable, versioned)
|
||||||
var agent = client.beta().agents().create(AgentCreateParams.builder()
|
var agent = client.beta().agents().create(AgentCreateParams.builder()
|
||||||
.name("Coding Assistant")
|
.name("Coding Assistant")
|
||||||
.model("claude-opus-4-7")
|
.model("claude-opus-4-8")
|
||||||
.system("You are a helpful coding assistant.")
|
.system("You are a helpful coding assistant.")
|
||||||
.addTool(BetaManagedAgentsAgentToolset20260401Params.builder()
|
.addTool(BetaManagedAgentsAgentToolset20260401Params.builder()
|
||||||
.type(BetaManagedAgentsAgentToolset20260401Params.Type.AGENT_TOOLSET_20260401)
|
.type(BetaManagedAgentsAgentToolset20260401Params.Type.AGENT_TOOLSET_20260401)
|
||||||
@@ -295,7 +295,7 @@ import com.anthropic.models.beta.agents.BetaManagedAgentsUrlmcpServerParams;
|
|||||||
// Agent declares MCP server (no auth here — auth goes in a vault)
|
// Agent declares MCP server (no auth here — auth goes in a vault)
|
||||||
var agent = client.beta().agents().create(AgentCreateParams.builder()
|
var agent = client.beta().agents().create(AgentCreateParams.builder()
|
||||||
.name("GitHub Assistant")
|
.name("GitHub Assistant")
|
||||||
.model("claude-opus-4-7")
|
.model("claude-opus-4-8")
|
||||||
.addMcpServer(BetaManagedAgentsUrlmcpServerParams.builder()
|
.addMcpServer(BetaManagedAgentsUrlmcpServerParams.builder()
|
||||||
.type(BetaManagedAgentsUrlmcpServerParams.Type.URL)
|
.type(BetaManagedAgentsUrlmcpServerParams.Type.URL)
|
||||||
.name("github")
|
.name("github")
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ $client = Foundry\Client::withCredentials(
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
$message = $client->messages->create(
|
$message = $client->messages->create(
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
maxTokens: 16000,
|
maxTokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
['role' => 'user', 'content' => 'What is the capital of France?'],
|
['role' => 'user', 'content' => 'What is the capital of France?'],
|
||||||
@@ -96,7 +96,7 @@ use Anthropic\Messages\RawContentBlockDeltaEvent;
|
|||||||
use Anthropic\Messages\TextDelta;
|
use Anthropic\Messages\TextDelta;
|
||||||
|
|
||||||
$stream = $client->messages->createStream(
|
$stream = $client->messages->createStream(
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
maxTokens: 64000,
|
maxTokens: 64000,
|
||||||
messages: [
|
messages: [
|
||||||
['role' => 'user', 'content' => 'Write a haiku'],
|
['role' => 'user', 'content' => 'Write a haiku'],
|
||||||
@@ -141,7 +141,7 @@ $weatherTool = new BetaRunnableTool(
|
|||||||
$runner = $client->beta->messages->toolRunner(
|
$runner = $client->beta->messages->toolRunner(
|
||||||
maxTokens: 16000,
|
maxTokens: 16000,
|
||||||
messages: [['role' => 'user', 'content' => 'What is the weather in Paris?']],
|
messages: [['role' => 'user', 'content' => 'What is the weather in Paris?']],
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
tools: [$weatherTool],
|
tools: [$weatherTool],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ $tools = [
|
|||||||
$messages = [['role' => 'user', 'content' => 'What is the weather in SF?']];
|
$messages = [['role' => 'user', 'content' => 'What is the weather in SF?']];
|
||||||
|
|
||||||
$response = $client->messages->create(
|
$response = $client->messages->create(
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
maxTokens: 16000,
|
maxTokens: 16000,
|
||||||
tools: $tools,
|
tools: $tools,
|
||||||
messages: $messages,
|
messages: $messages,
|
||||||
@@ -205,7 +205,7 @@ while ($response->stopReason === 'tool_use') { // camelCase property
|
|||||||
$messages[] = ['role' => 'user', 'content' => $toolResults];
|
$messages[] = ['role' => 'user', 'content' => $toolResults];
|
||||||
|
|
||||||
$response = $client->messages->create(
|
$response = $client->messages->create(
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
maxTokens: 16000,
|
maxTokens: 16000,
|
||||||
tools: $tools,
|
tools: $tools,
|
||||||
messages: $messages,
|
messages: $messages,
|
||||||
@@ -233,7 +233,7 @@ foreach ($response->content as $block) {
|
|||||||
use Anthropic\Messages\ThinkingBlock;
|
use Anthropic\Messages\ThinkingBlock;
|
||||||
|
|
||||||
$message = $client->messages->create(
|
$message = $client->messages->create(
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
maxTokens: 16000,
|
maxTokens: 16000,
|
||||||
thinking: ['type' => 'adaptive'],
|
thinking: ['type' => 'adaptive'],
|
||||||
messages: [
|
messages: [
|
||||||
@@ -265,7 +265,7 @@ foreach ($message->content as $block) {
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
$message = $client->messages->create(
|
$message = $client->messages->create(
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
maxTokens: 16000,
|
maxTokens: 16000,
|
||||||
system: [
|
system: [
|
||||||
['type' => 'text', 'text' => $longSystemPrompt, 'cacheControl' => ['type' => 'ephemeral']],
|
['type' => 'text', 'text' => $longSystemPrompt, 'cacheControl' => ['type' => 'ephemeral']],
|
||||||
@@ -304,7 +304,7 @@ class Person implements StructuredOutputModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
$message = $client->messages->create(
|
$message = $client->messages->create(
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
maxTokens: 16000,
|
maxTokens: 16000,
|
||||||
messages: [['role' => 'user', 'content' => 'Generate a profile for Alice, age 30']],
|
messages: [['role' => 'user', 'content' => 'Generate a profile for Alice, age 30']],
|
||||||
outputConfig: ['format' => Person::class],
|
outputConfig: ['format' => Person::class],
|
||||||
@@ -320,7 +320,7 @@ Types are inferred from PHP type hints. Use `#[Constrained(description: '...')]`
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
$message = $client->messages->create(
|
$message = $client->messages->create(
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
maxTokens: 16000,
|
maxTokens: 16000,
|
||||||
messages: [['role' => 'user', 'content' => 'Extract: John (john@co.com), Enterprise plan']],
|
messages: [['role' => 'user', 'content' => 'Extract: John (john@co.com), Enterprise plan']],
|
||||||
outputConfig: [
|
outputConfig: [
|
||||||
@@ -359,7 +359,7 @@ foreach ($message->content as $block) {
|
|||||||
use Anthropic\Beta\Messages\BetaRequestMCPServerURLDefinition;
|
use Anthropic\Beta\Messages\BetaRequestMCPServerURLDefinition;
|
||||||
|
|
||||||
$response = $client->beta->messages->create(
|
$response = $client->beta->messages->create(
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
maxTokens: 16000,
|
maxTokens: 16000,
|
||||||
mcpServers: [
|
mcpServers: [
|
||||||
BetaRequestMCPServerURLDefinition::with(
|
BetaRequestMCPServerURLDefinition::with(
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ use Anthropic\Beta\Agents\BetaManagedAgentsAgentToolset20260401Params;
|
|||||||
// 1. Create the agent (reusable, versioned)
|
// 1. Create the agent (reusable, versioned)
|
||||||
$agent = $client->beta->agents->create(
|
$agent = $client->beta->agents->create(
|
||||||
name: 'Coding Assistant',
|
name: 'Coding Assistant',
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
system: 'You are a helpful coding assistant.',
|
system: 'You are a helpful coding assistant.',
|
||||||
tools: [
|
tools: [
|
||||||
BetaManagedAgentsAgentToolset20260401Params::with(
|
BetaManagedAgentsAgentToolset20260401Params::with(
|
||||||
@@ -299,7 +299,7 @@ use Anthropic\Beta\Sessions\BetaManagedAgentsAgentParams;
|
|||||||
// Agent declares MCP server (no auth here — auth goes in a vault)
|
// Agent declares MCP server (no auth here — auth goes in a vault)
|
||||||
$agent = $client->beta->agents->create(
|
$agent = $client->beta->agents->create(
|
||||||
name: 'GitHub Assistant',
|
name: 'GitHub Assistant',
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
mcpServers: [
|
mcpServers: [
|
||||||
BetaManagedAgentsUrlmcpServerParams::with(
|
BetaManagedAgentsUrlmcpServerParams::with(
|
||||||
type: 'url',
|
type: 'url',
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ async_client = anthropic.AsyncAnthropic()
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[
|
messages=[
|
||||||
{"role": "user", "content": "What is the capital of France?"}
|
{"role": "user", "content": "What is the capital of France?"}
|
||||||
@@ -46,7 +46,7 @@ for block in response.content:
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
system="You are a helpful coding assistant. Always provide examples in Python.",
|
system="You are a helpful coding assistant. Always provide examples in Python.",
|
||||||
messages=[{"role": "user", "content": "How do I read a JSON file?"}]
|
messages=[{"role": "user", "content": "How do I read a JSON file?"}]
|
||||||
@@ -66,7 +66,7 @@ with open("image.png", "rb") as f:
|
|||||||
image_data = base64.standard_b64encode(f.read()).decode("utf-8")
|
image_data = base64.standard_b64encode(f.read()).decode("utf-8")
|
||||||
|
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{
|
messages=[{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
@@ -89,7 +89,7 @@ response = client.messages.create(
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{
|
messages=[{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
@@ -119,7 +119,7 @@ Use top-level `cache_control` to automatically cache the last cacheable block in
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
cache_control={"type": "ephemeral"}, # auto-caches the last cacheable block
|
cache_control={"type": "ephemeral"}, # auto-caches the last cacheable block
|
||||||
system="You are an expert on this large document...",
|
system="You are an expert on this large document...",
|
||||||
@@ -133,7 +133,7 @@ For fine-grained control, add `cache_control` to specific content blocks:
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
system=[{
|
system=[{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
@@ -145,7 +145,7 @@ response = client.messages.create(
|
|||||||
|
|
||||||
# With explicit TTL (time-to-live)
|
# With explicit TTL (time-to-live)
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
system=[{
|
system=[{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
@@ -170,13 +170,13 @@ If `cache_read_input_tokens` is zero across repeated identical-prefix requests,
|
|||||||
|
|
||||||
## Extended Thinking
|
## Extended Thinking
|
||||||
|
|
||||||
> **Opus 4.7, Opus 4.6, and Sonnet 4.6:** Use adaptive thinking. `budget_tokens` is removed on Opus 4.7 (400 if sent); deprecated on Opus 4.6 and Sonnet 4.6.
|
> **Opus 4.8, Opus 4.7, Opus 4.6, and Sonnet 4.6:** Use adaptive thinking. `budget_tokens` is removed on Opus 4.8 and 4.7 (400 if sent); deprecated on Opus 4.6 and Sonnet 4.6.
|
||||||
> **Older models:** Use `thinking: {type: "enabled", budget_tokens: N}` (must be < `max_tokens`, min 1024).
|
> **Older models:** Use `thinking: {type: "enabled", budget_tokens: N}` (must be < `max_tokens`, min 1024).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Opus 4.7 / 4.6: adaptive thinking (recommended)
|
# Opus 4.8 / 4.7 / 4.6: adaptive thinking (recommended)
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
thinking={"type": "adaptive"},
|
thinking={"type": "adaptive"},
|
||||||
output_config={"effort": "high"}, # low | medium | high | max
|
output_config={"effort": "high"}, # low | medium | high | max
|
||||||
@@ -258,7 +258,7 @@ class ConversationManager:
|
|||||||
# Usage
|
# Usage
|
||||||
conversation = ConversationManager(
|
conversation = ConversationManager(
|
||||||
client=anthropic.Anthropic(),
|
client=anthropic.Anthropic(),
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
system="You are a helpful assistant."
|
system="You are a helpful assistant."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ response2 = conversation.send("What's my name?") # Claude remembers "Alice"
|
|||||||
|
|
||||||
### Compaction (long conversations)
|
### Compaction (long conversations)
|
||||||
|
|
||||||
> **Beta, Opus 4.7, Opus 4.6, and Sonnet 4.6.** When conversations approach the 200K context window, compaction automatically summarizes earlier context server-side. The API returns a `compaction` block; you must pass it back on subsequent requests — append `response.content`, not just the text.
|
> **Beta, Opus 4.8, Opus 4.7, Opus 4.6, and Sonnet 4.6.** When conversations approach the 200K context window, compaction automatically summarizes earlier context server-side. The API returns a `compaction` block; you must pass it back on subsequent requests — append `response.content`, not just the text.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import anthropic
|
import anthropic
|
||||||
@@ -288,7 +288,7 @@ def chat(user_message: str) -> str:
|
|||||||
|
|
||||||
response = client.beta.messages.create(
|
response = client.beta.messages.create(
|
||||||
betas=["compact-2026-01-12"],
|
betas=["compact-2026-01-12"],
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=messages,
|
messages=messages,
|
||||||
context_management={
|
context_management={
|
||||||
@@ -331,7 +331,7 @@ The `stop_reason` field in the response indicates why the model stopped generati
|
|||||||
```python
|
```python
|
||||||
# Automatic caching (simplest — caches the last cacheable block)
|
# Automatic caching (simplest — caches the last cacheable block)
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
cache_control={"type": "ephemeral"},
|
cache_control={"type": "ephemeral"},
|
||||||
system=large_document_text, # e.g., 50KB of context
|
system=large_document_text, # e.g., 50KB of context
|
||||||
@@ -347,7 +347,7 @@ response = client.messages.create(
|
|||||||
```python
|
```python
|
||||||
# Default to Opus for most tasks
|
# Default to Opus for most tasks
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7", # $5.00/$25.00 per 1M tokens
|
model="claude-opus-4-8", # $5.00/$25.00 per 1M tokens
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{"role": "user", "content": "Explain quantum computing"}]
|
messages=[{"role": "user", "content": "Explain quantum computing"}]
|
||||||
)
|
)
|
||||||
@@ -371,7 +371,7 @@ simple_response = client.messages.create(
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
count_response = client.messages.count_tokens(
|
count_response = client.messages.count_tokens(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
messages=messages,
|
messages=messages,
|
||||||
system=system
|
system=system
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ message_batch = client.messages.batches.create(
|
|||||||
Request(
|
Request(
|
||||||
custom_id="request-1",
|
custom_id="request-1",
|
||||||
params=MessageCreateParamsNonStreaming(
|
params=MessageCreateParamsNonStreaming(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{"role": "user", "content": "Summarize climate change impacts"}]
|
messages=[{"role": "user", "content": "Summarize climate change impacts"}]
|
||||||
)
|
)
|
||||||
@@ -34,7 +34,7 @@ message_batch = client.messages.batches.create(
|
|||||||
Request(
|
Request(
|
||||||
custom_id="request-2",
|
custom_id="request-2",
|
||||||
params=MessageCreateParamsNonStreaming(
|
params=MessageCreateParamsNonStreaming(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{"role": "user", "content": "Explain quantum computing basics"}]
|
messages=[{"role": "user", "content": "Explain quantum computing basics"}]
|
||||||
)
|
)
|
||||||
@@ -117,7 +117,7 @@ message_batch = client.messages.batches.create(
|
|||||||
Request(
|
Request(
|
||||||
custom_id=f"analysis-{i}",
|
custom_id=f"analysis-{i}",
|
||||||
params=MessageCreateParamsNonStreaming(
|
params=MessageCreateParamsNonStreaming(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
system=shared_system,
|
system=shared_system,
|
||||||
messages=[{"role": "user", "content": question}]
|
messages=[{"role": "user", "content": question}]
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ print(f"Size: {uploaded.size_bytes} bytes")
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.beta.messages.create(
|
response = client.beta.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{
|
messages=[{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
@@ -65,7 +65,7 @@ image_file = client.beta.files.upload(
|
|||||||
)
|
)
|
||||||
|
|
||||||
response = client.beta.messages.create(
|
response = client.beta.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{
|
messages=[{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
@@ -142,7 +142,7 @@ questions = [
|
|||||||
|
|
||||||
for question in questions:
|
for question in questions:
|
||||||
response = client.beta.messages.create(
|
response = client.beta.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{
|
messages=[{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
with client.messages.stream(
|
with client.messages.stream(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=64000,
|
max_tokens=64000,
|
||||||
messages=[{"role": "user", "content": "Write a story"}]
|
messages=[{"role": "user", "content": "Write a story"}]
|
||||||
) as stream:
|
) as stream:
|
||||||
@@ -16,7 +16,7 @@ with client.messages.stream(
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
async with async_client.messages.stream(
|
async with async_client.messages.stream(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=64000,
|
max_tokens=64000,
|
||||||
messages=[{"role": "user", "content": "Write a story"}]
|
messages=[{"role": "user", "content": "Write a story"}]
|
||||||
) as stream:
|
) as stream:
|
||||||
@@ -30,11 +30,11 @@ async with async_client.messages.stream(
|
|||||||
|
|
||||||
Claude may return text, thinking blocks, or tool use. Handle each appropriately:
|
Claude may return text, thinking blocks, or tool use. Handle each appropriately:
|
||||||
|
|
||||||
> **Opus 4.7 / Opus 4.6:** Use `thinking: {type: "adaptive"}`. On older models, use `thinking: {type: "enabled", budget_tokens: N}` instead.
|
> **Opus 4.8 / Opus 4.7 / Opus 4.6:** Use `thinking: {type: "adaptive"}`. On older models, use `thinking: {type: "enabled", budget_tokens: N}` instead.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
with client.messages.stream(
|
with client.messages.stream(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=64000,
|
max_tokens=64000,
|
||||||
thinking={"type": "adaptive"},
|
thinking={"type": "adaptive"},
|
||||||
messages=[{"role": "user", "content": "Analyze this problem"}]
|
messages=[{"role": "user", "content": "Analyze this problem"}]
|
||||||
@@ -61,7 +61,7 @@ The Python tool runner currently returns complete messages. Use streaming for in
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
with client.messages.stream(
|
with client.messages.stream(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=64000,
|
max_tokens=64000,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
messages=messages
|
messages=messages
|
||||||
@@ -79,7 +79,7 @@ with client.messages.stream(
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
with client.messages.stream(
|
with client.messages.stream(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=64000,
|
max_tokens=64000,
|
||||||
messages=[{"role": "user", "content": "Hello"}]
|
messages=[{"role": "user", "content": "Hello"}]
|
||||||
) as stream:
|
) as stream:
|
||||||
@@ -126,7 +126,7 @@ def stream_with_progress(client, **kwargs):
|
|||||||
```python
|
```python
|
||||||
try:
|
try:
|
||||||
with client.messages.stream(
|
with client.messages.stream(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=64000,
|
max_tokens=64000,
|
||||||
messages=[{"role": "user", "content": "Write a story"}]
|
messages=[{"role": "user", "content": "Write a story"}]
|
||||||
) as stream:
|
) as stream:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ def get_weather(location: str, unit: str = "celsius") -> str:
|
|||||||
|
|
||||||
# The tool runner handles the agentic loop automatically
|
# The tool runner handles the agentic loop automatically
|
||||||
runner = client.beta.messages.tool_runner(
|
runner = client.beta.messages.tool_runner(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
tools=[get_weather],
|
tools=[get_weather],
|
||||||
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
|
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
|
||||||
@@ -72,7 +72,7 @@ async with stdio_client(StdioServerParameters(command="mcp-server")) as (read, w
|
|||||||
tools_result = await mcp_client.list_tools()
|
tools_result = await mcp_client.list_tools()
|
||||||
# tool_runner is sync — returns the runner, not a coroutine
|
# tool_runner is sync — returns the runner, not a coroutine
|
||||||
runner = client.beta.messages.tool_runner(
|
runner = client.beta.messages.tool_runner(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{"role": "user", "content": "Use the available tools"}],
|
messages=[{"role": "user", "content": "Use the available tools"}],
|
||||||
tools=[async_mcp_tool(t, mcp_client) for t in tools_result.tools],
|
tools=[async_mcp_tool(t, mcp_client) for t in tools_result.tools],
|
||||||
@@ -90,7 +90,7 @@ from anthropic.lib.tools.mcp import mcp_message
|
|||||||
|
|
||||||
prompt = await mcp_client.get_prompt(name="my-prompt")
|
prompt = await mcp_client.get_prompt(name="my-prompt")
|
||||||
response = await client.beta.messages.create(
|
response = await client.beta.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[mcp_message(m) for m in prompt.messages],
|
messages=[mcp_message(m) for m in prompt.messages],
|
||||||
)
|
)
|
||||||
@@ -103,7 +103,7 @@ from anthropic.lib.tools.mcp import mcp_resource_to_content
|
|||||||
|
|
||||||
resource = await mcp_client.read_resource(uri="file:///path/to/doc.txt")
|
resource = await mcp_client.read_resource(uri="file:///path/to/doc.txt")
|
||||||
response = await client.beta.messages.create(
|
response = await client.beta.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{
|
messages=[{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
@@ -142,7 +142,7 @@ messages = [{"role": "user", "content": user_input}]
|
|||||||
# Agentic loop: keep going until Claude stops calling tools
|
# Agentic loop: keep going until Claude stops calling tools
|
||||||
while True:
|
while True:
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
messages=messages
|
messages=messages
|
||||||
@@ -189,7 +189,7 @@ final_text = next(b.text for b in response.content if b.type == "text")
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
messages=[{"role": "user", "content": "What's the weather in Paris?"}]
|
messages=[{"role": "user", "content": "What's the weather in Paris?"}]
|
||||||
@@ -204,7 +204,7 @@ for block in response.content:
|
|||||||
result = execute_tool(tool_name, tool_input)
|
result = execute_tool(tool_name, tool_input)
|
||||||
|
|
||||||
followup = client.messages.create(
|
followup = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
messages=[
|
messages=[
|
||||||
@@ -241,7 +241,7 @@ for block in response.content:
|
|||||||
# Send all results back at once
|
# Send all results back at once
|
||||||
if tool_results:
|
if tool_results:
|
||||||
followup = client.messages.create(
|
followup = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
messages=[
|
messages=[
|
||||||
@@ -271,7 +271,7 @@ tool_result = {
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
tool_choice={"type": "tool", "name": "get_weather"}, # Force specific tool
|
tool_choice={"type": "tool", "name": "get_weather"}, # Force specific tool
|
||||||
@@ -291,7 +291,7 @@ import anthropic
|
|||||||
client = anthropic.Anthropic()
|
client = anthropic.Anthropic()
|
||||||
|
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{
|
messages=[{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
@@ -319,7 +319,7 @@ uploaded = client.beta.files.upload(file=open("sales_data.csv", "rb"))
|
|||||||
# 2. Pass to code execution via container_upload block
|
# 2. Pass to code execution via container_upload block
|
||||||
# Code execution is GA; Files API is still beta (pass via extra_headers)
|
# Code execution is GA; Files API is still beta (pass via extra_headers)
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
extra_headers={"anthropic-beta": "files-api-2025-04-14"},
|
extra_headers={"anthropic-beta": "files-api-2025-04-14"},
|
||||||
messages=[{
|
messages=[{
|
||||||
@@ -364,7 +364,7 @@ for block in response.content:
|
|||||||
```python
|
```python
|
||||||
# First request: set up environment
|
# First request: set up environment
|
||||||
response1 = client.messages.create(
|
response1 = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{"role": "user", "content": "Install tabulate and create data.json with sample data"}],
|
messages=[{"role": "user", "content": "Install tabulate and create data.json with sample data"}],
|
||||||
tools=[{"type": "code_execution_20260120", "name": "code_execution"}]
|
tools=[{"type": "code_execution_20260120", "name": "code_execution"}]
|
||||||
@@ -376,7 +376,7 @@ container_id = response1.container.id
|
|||||||
# Second request: reuse the same container
|
# Second request: reuse the same container
|
||||||
response2 = client.messages.create(
|
response2 = client.messages.create(
|
||||||
container=container_id,
|
container=container_id,
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{"role": "user", "content": "Read data.json and display as a formatted table"}],
|
messages=[{"role": "user", "content": "Read data.json and display as a formatted table"}],
|
||||||
tools=[{"type": "code_execution_20260120", "name": "code_execution"}]
|
tools=[{"type": "code_execution_20260120", "name": "code_execution"}]
|
||||||
@@ -416,7 +416,7 @@ import anthropic
|
|||||||
client = anthropic.Anthropic()
|
client = anthropic.Anthropic()
|
||||||
|
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{"role": "user", "content": "Remember that my preferred language is Python."}],
|
messages=[{"role": "user", "content": "Remember that my preferred language is Python."}],
|
||||||
tools=[{"type": "memory_20250818", "name": "memory"}],
|
tools=[{"type": "memory_20250818", "name": "memory"}],
|
||||||
@@ -442,7 +442,7 @@ memory = MyMemoryTool()
|
|||||||
|
|
||||||
# Use with tool runner
|
# Use with tool runner
|
||||||
runner = client.beta.messages.tool_runner(
|
runner = client.beta.messages.tool_runner(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
tools=[memory],
|
tools=[memory],
|
||||||
messages=[{"role": "user", "content": "Remember my preferences"}],
|
messages=[{"role": "user", "content": "Remember my preferences"}],
|
||||||
@@ -477,7 +477,7 @@ class ContactInfo(BaseModel):
|
|||||||
client = anthropic.Anthropic()
|
client = anthropic.Anthropic()
|
||||||
|
|
||||||
response = client.messages.parse(
|
response = client.messages.parse(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{
|
messages=[{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
@@ -496,7 +496,7 @@ print(contact.interests) # ["API", "SDKs"]
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{
|
messages=[{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
@@ -530,7 +530,7 @@ data = json.loads(text)
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{"role": "user", "content": "Book a flight to Tokyo for 2 passengers on March 15"}],
|
messages=[{"role": "user", "content": "Book a flight to Tokyo for 2 passengers on March 15"}],
|
||||||
tools=[{
|
tools=[{
|
||||||
@@ -555,7 +555,7 @@ response = client.messages.create(
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
max_tokens=16000,
|
max_tokens=16000,
|
||||||
messages=[{"role": "user", "content": "Plan a trip to Paris next month"}],
|
messages=[{"role": "user", "content": "Plan a trip to Paris next month"}],
|
||||||
output_config={
|
output_config={
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ print(environment.id) # env_...
|
|||||||
# 1. Create the agent (reusable, versioned)
|
# 1. Create the agent (reusable, versioned)
|
||||||
agent = client.beta.agents.create(
|
agent = client.beta.agents.create(
|
||||||
name="Coding Assistant",
|
name="Coding Assistant",
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
tools=[{"type": "agent_toolset_20260401", "default_config": {"enabled": True}}],
|
tools=[{"type": "agent_toolset_20260401", "default_config": {"enabled": True}}],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ import os
|
|||||||
|
|
||||||
agent = client.beta.agents.create(
|
agent = client.beta.agents.create(
|
||||||
name="Code Reviewer",
|
name="Code Reviewer",
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
system="You are a senior code reviewer.",
|
system="You are a senior code reviewer.",
|
||||||
tools=[
|
tools=[
|
||||||
{"type": "agent_toolset_20260401"},
|
{"type": "agent_toolset_20260401"},
|
||||||
@@ -311,7 +311,7 @@ client.beta.sessions.archive(session_id="sesn_011CZxAbc123Def456")
|
|||||||
# Agent declares MCP server (no auth here — auth goes in a vault)
|
# Agent declares MCP server (no auth here — auth goes in a vault)
|
||||||
agent = client.beta.agents.create(
|
agent = client.beta.agents.create(
|
||||||
name="MCP Agent",
|
name="MCP Agent",
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
mcp_servers=[
|
mcp_servers=[
|
||||||
{"type": "url", "name": "my-tools", "url": "https://my-mcp-server.example.com/sse"},
|
{"type": "url", "name": "my-tools", "url": "https://my-mcp-server.example.com/sse"},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ client = Anthropic::Client.new(api_key: "your-api-key")
|
|||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
message = client.messages.create(
|
message = client.messages.create(
|
||||||
model: :"claude-opus-4-7",
|
model: :"claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{ role: "user", content: "What is the capital of France?" }
|
{ role: "user", content: "What is the capital of France?" }
|
||||||
@@ -46,7 +46,7 @@ end
|
|||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
stream = client.messages.stream(
|
stream = client.messages.stream(
|
||||||
model: :"claude-opus-4-7",
|
model: :"claude-opus-4-8",
|
||||||
max_tokens: 64000,
|
max_tokens: 64000,
|
||||||
messages: [{ role: "user", content: "Write a haiku" }]
|
messages: [{ role: "user", content: "Write a haiku" }]
|
||||||
)
|
)
|
||||||
@@ -78,7 +78,7 @@ class GetWeather < Anthropic::BaseTool
|
|||||||
end
|
end
|
||||||
|
|
||||||
client.beta.messages.tool_runner(
|
client.beta.messages.tool_runner(
|
||||||
model: :"claude-opus-4-7",
|
model: :"claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
tools: [GetWeather.new],
|
tools: [GetWeather.new],
|
||||||
messages: [{ role: "user", content: "What's the weather in San Francisco?" }]
|
messages: [{ role: "user", content: "What's the weather in San Francisco?" }]
|
||||||
@@ -99,7 +99,7 @@ See the [shared tool use concepts](../shared/tool-use-concepts.md) for the tool
|
|||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
message = client.messages.create(
|
message = client.messages.create(
|
||||||
model: :"claude-opus-4-7",
|
model: :"claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
system_: [
|
system_: [
|
||||||
{ type: "text", text: long_system_prompt, cache_control: { type: "ephemeral" } }
|
{ type: "text", text: long_system_prompt, cache_control: { type: "ephemeral" } }
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ puts "Environment ID: #{environment.id}" # env_...
|
|||||||
# 1. Create the agent (reusable, versioned)
|
# 1. Create the agent (reusable, versioned)
|
||||||
agent = client.beta.agents.create(
|
agent = client.beta.agents.create(
|
||||||
name: "Coding Assistant",
|
name: "Coding Assistant",
|
||||||
model: :"claude-opus-4-7",
|
model: :"claude-opus-4-8",
|
||||||
system_: "You are a helpful coding assistant.",
|
system_: "You are a helpful coding assistant.",
|
||||||
tools: [{type: "agent_toolset_20260401"}]
|
tools: [{type: "agent_toolset_20260401"}]
|
||||||
)
|
)
|
||||||
@@ -260,7 +260,7 @@ client.beta.sessions.delete(session.id)
|
|||||||
# Agent declares MCP server (no auth here — auth goes in a vault)
|
# Agent declares MCP server (no auth here — auth goes in a vault)
|
||||||
agent = client.beta.agents.create(
|
agent = client.beta.agents.create(
|
||||||
name: "GitHub Assistant",
|
name: "GitHub Assistant",
|
||||||
model: :"claude-opus-4-7",
|
model: :"claude-opus-4-8",
|
||||||
mcp_servers: [
|
mcp_servers: [
|
||||||
{
|
{
|
||||||
type: "url",
|
type: "url",
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ This file documents HTTP error codes returned by the Claude API, their common ca
|
|||||||
- Using deprecated model ID
|
- Using deprecated model ID
|
||||||
- Invalid API endpoint
|
- Invalid API endpoint
|
||||||
|
|
||||||
**Fix:** Use exact model IDs from the models documentation. You can use aliases (e.g., `claude-opus-4-7`).
|
**Fix:** Use exact model IDs from the models documentation. You can use aliases (e.g., `claude-opus-4-8`).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ Some 400 errors are specifically related to parameter validation:
|
|||||||
- `budget_tokens` >= `max_tokens` in extended thinking
|
- `budget_tokens` >= `max_tokens` in extended thinking
|
||||||
- Invalid tool definition schema
|
- Invalid tool definition schema
|
||||||
|
|
||||||
**Model-specific 400s on Opus 4.7:**
|
**Model-specific 400s on Opus 4.8 / 4.7:**
|
||||||
|
|
||||||
- `temperature`, `top_p`, `top_k` are removed — sending any of them returns 400. Delete the parameter; see `shared/model-migration.md` → Per-SDK Syntax Reference.
|
- `temperature`, `top_p`, `top_k` are removed — sending any of them returns 400. Delete the parameter; see `shared/model-migration.md` → Per-SDK Syntax Reference.
|
||||||
- `thinking: {type: "enabled", budget_tokens: N}` is removed — sending it returns 400. Use `thinking: {type: "adaptive"}` instead.
|
- `thinking: {type: "enabled", budget_tokens: N}` is removed — sending it returns 400. Use `thinking: {type: "adaptive"}` instead.
|
||||||
@@ -166,10 +166,10 @@ thinking: budget_tokens=10000, max_tokens=16000
|
|||||||
|
|
||||||
| Mistake | Error | Fix |
|
| Mistake | Error | Fix |
|
||||||
| ------------------------------- | ---------------- | ------------------------------------------------------- |
|
| ------------------------------- | ---------------- | ------------------------------------------------------- |
|
||||||
| `temperature`/`top_p`/`top_k` on Opus 4.7 | 400 | Remove the parameter (see `shared/model-migration.md`) |
|
| `temperature`/`top_p`/`top_k` on Opus 4.8 / 4.7 | 400 | Remove the parameter (see `shared/model-migration.md`) |
|
||||||
| `budget_tokens` on Opus 4.7 | 400 | Use `thinking: {type: "adaptive"}` |
|
| `budget_tokens` on Opus 4.8 / 4.7 | 400 | Use `thinking: {type: "adaptive"}` |
|
||||||
| `budget_tokens` >= `max_tokens` (older models) | 400 | Ensure `budget_tokens` < `max_tokens` |
|
| `budget_tokens` >= `max_tokens` (older models) | 400 | Ensure `budget_tokens` < `max_tokens` |
|
||||||
| Typo in model ID | 404 | Use valid model ID like `claude-opus-4-7` |
|
| Typo in model ID | 404 | Use valid model ID like `claude-opus-4-8` |
|
||||||
| First message is `assistant` | 400 | First message must be `user` |
|
| First message is `assistant` | 400 | First message must be `user` |
|
||||||
| Consecutive same-role messages | 400 | Alternate `user` and `assistant` |
|
| Consecutive same-role messages | 400 | Alternate `user` and `assistant` |
|
||||||
| API key in code | 401 (leaked key) | Use environment variable |
|
| API key in code | 401 (leaked key) | Use environment variable |
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ This file contains WebFetch URLs for fetching current information from platform.
|
|||||||
| Topic | URL | Extraction Prompt |
|
| Topic | URL | Extraction Prompt |
|
||||||
| ----------------- | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
| ----------------- | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
||||||
| Extended Thinking | `https://platform.claude.com/docs/en/build-with-claude/extended-thinking.md` | "Extract extended thinking parameters, budget_tokens requirements, and usage examples" |
|
| Extended Thinking | `https://platform.claude.com/docs/en/build-with-claude/extended-thinking.md` | "Extract extended thinking parameters, budget_tokens requirements, and usage examples" |
|
||||||
| Adaptive Thinking | `https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking.md` | "Extract adaptive thinking setup, effort levels, and Claude Opus 4.7 usage examples" |
|
| Adaptive Thinking | `https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking.md` | "Extract adaptive thinking setup, effort levels, and Claude Opus 4.8 usage examples" |
|
||||||
| Effort Parameter | `https://platform.claude.com/docs/en/build-with-claude/effort.md` | "Extract effort levels, cost-quality tradeoffs, and interaction with thinking" |
|
| Effort Parameter | `https://platform.claude.com/docs/en/build-with-claude/effort.md` | "Extract effort levels, cost-quality tradeoffs, and interaction with thinking" |
|
||||||
| Tool Use | `https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview.md` | "Extract tool definition schema, tool_choice options, and handling tool results" |
|
| Tool Use | `https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview.md` | "Extract tool definition schema, tool_choice options, and handling tool results" |
|
||||||
| Streaming | `https://platform.claude.com/docs/en/build-with-claude/streaming.md` | "Extract streaming event types, SDK examples, and best practices" |
|
| Streaming | `https://platform.claude.com/docs/en/build-with-claude/streaming.md` | "Extract streaming event types, SDK examples, and best practices" |
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ All resources are under the `beta` namespace. Python and TypeScript share identi
|
|||||||
|
|
||||||
**Agent shorthand:** `agent` on session create accepts either a bare string (`agent="agent_abc123"` — uses latest version) or the full reference object (`{type: "agent", id: "agent_abc123", version: 123}`).
|
**Agent shorthand:** `agent` on session create accepts either a bare string (`agent="agent_abc123"` — uses latest version) or the full reference object (`{type: "agent", id: "agent_abc123", version: 123}`).
|
||||||
|
|
||||||
**Model shorthand:** `model` on agent create accepts either a bare string (`model="claude-opus-4-7"` — uses `standard` speed) or the full config object (`{id: "claude-opus-4-6", speed: "fast"}`). Note: `speed: "fast"` is only supported on Opus 4.6.
|
**Model shorthand:** `model` on agent create accepts either a bare string (`model="claude-opus-4-8"` — uses `standard` speed) or the full config object (`{id: "claude-opus-4-6", speed: "fast"}`). Note: `speed: "fast"` is only supported on Opus 4.6.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ Immutable per-mutation snapshots (`memver_...`) — the audit and rollback surfa
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"name": "string (required, 1-256 chars)",
|
"name": "string (required, 1-256 chars)",
|
||||||
"model": "claude-opus-4-7 (required — bare string, or {id, speed} object)",
|
"model": "claude-opus-4-8 (required — bare string, or {id, speed} object)",
|
||||||
"description": "string (optional, up to 2048 chars)",
|
"description": "string (optional, up to 2048 chars)",
|
||||||
"system": "string (optional, up to 100,000 chars)",
|
"system": "string (optional, up to 100,000 chars)",
|
||||||
"tools": [
|
"tools": [
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ Key fields returned by the API:
|
|||||||
const agent = await client.beta.agents.create(
|
const agent = await client.beta.agents.create(
|
||||||
{
|
{
|
||||||
name: "Coding Assistant",
|
name: "Coding Assistant",
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
system: "You are a helpful coding agent.",
|
system: "You are a helpful coding agent.",
|
||||||
tools: [{ type: "agent_toolset_20260401"}],
|
tools: [{ type: "agent_toolset_20260401"}],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ Repositories are attached for the lifetime of the session — to change which re
|
|||||||
const agent = await client.beta.agents.create(
|
const agent = await client.beta.agents.create(
|
||||||
{
|
{
|
||||||
name: 'GitHub Agent',
|
name: 'GitHub Agent',
|
||||||
model: 'claude-opus-4-7',
|
model: 'claude-opus-4-8',
|
||||||
mcp_servers: [
|
mcp_servers: [
|
||||||
{ type: 'url', name: 'github', url: 'https://api.githubcopilot.com/mcp/' },
|
{ type: 'url', name: 'github', url: 'https://api.githubcopilot.com/mcp/' },
|
||||||
],
|
],
|
||||||
@@ -173,7 +173,7 @@ import os
|
|||||||
|
|
||||||
agent = client.beta.agents.create(
|
agent = client.beta.agents.create(
|
||||||
name="GitHub Agent",
|
name="GitHub Agent",
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
mcp_servers=[{
|
mcp_servers=[{
|
||||||
"type": "url",
|
"type": "url",
|
||||||
"name": "github",
|
"name": "github",
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ The SDK sets the `managed-agents-2026-04-01` beta header automatically on all `c
|
|||||||
```python
|
```python
|
||||||
orchestrator = client.beta.agents.create(
|
orchestrator = client.beta.agents.create(
|
||||||
name="Engineering Lead",
|
name="Engineering Lead",
|
||||||
model="{{OPUS_ID}}",
|
model="claude-opus-4-8",
|
||||||
system="You coordinate engineering work. Delegate code review to the reviewer and test writing to the test agent.",
|
system="You coordinate engineering work. Delegate code review to the reviewer and test writing to the test agent.",
|
||||||
tools=[{"type": "agent_toolset_20260401"}],
|
tools=[{"type": "agent_toolset_20260401"}],
|
||||||
multiagent={
|
multiagent={
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ Emit as `resources: [{type: "file", file_id, mount_path}]`. Max 999 file resourc
|
|||||||
- [ ] Networking: unrestricted internet from the container, or lock egress to specific hosts? (If locked, MCP server domains must be in `allowed_hosts` or tools silently fail.)
|
- [ ] Networking: unrestricted internet from the container, or lock egress to specific hosts? (If locked, MCP server domains must be in `allowed_hosts` or tools silently fail.)
|
||||||
- [ ] Name?
|
- [ ] Name?
|
||||||
- [ ] Job (one or two sentences — becomes the system prompt)?
|
- [ ] Job (one or two sentences — becomes the system prompt)?
|
||||||
- [ ] Model? (default `claude-opus-4-7`)
|
- [ ] Model? (default `claude-opus-4-8`)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ Skills are attached to the **agent** definition via `agents.create()`:
|
|||||||
const agent = await client.beta.agents.create(
|
const agent = await client.beta.agents.create(
|
||||||
{
|
{
|
||||||
name: "Financial Agent",
|
name: "Financial Agent",
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
system: "You are a financial analysis agent.",
|
system: "You are a financial analysis agent.",
|
||||||
skills: [
|
skills: [
|
||||||
{ type: "anthropic", skill_id: "xlsx" },
|
{ type: "anthropic", skill_id: "xlsx" },
|
||||||
@@ -289,7 +289,7 @@ Python:
|
|||||||
```python
|
```python
|
||||||
agent = client.beta.agents.create(
|
agent = client.beta.agents.create(
|
||||||
name="Financial Agent",
|
name="Financial Agent",
|
||||||
model="claude-opus-4-7",
|
model="claude-opus-4-8",
|
||||||
system="You are a financial analysis agent.",
|
system="You are a financial analysis agent.",
|
||||||
skills=[
|
skills=[
|
||||||
{"type": "anthropic", "skill_id": "xlsx"},
|
{"type": "anthropic", "skill_id": "xlsx"},
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ For the latest, authoritative version (with code samples in every supported lang
|
|||||||
| Breaking Changes by Source Model | Migrating to Opus 4.6 / Sonnet 4.6 |
|
| Breaking Changes by Source Model | Migrating to Opus 4.6 / Sonnet 4.6 |
|
||||||
| Migrating to Opus 4.7 | Migrating to Opus 4.7 (breaking changes, silent defaults, behavioral shifts) |
|
| Migrating to Opus 4.7 | Migrating to Opus 4.7 (breaking changes, silent defaults, behavioral shifts) |
|
||||||
| Opus 4.7 Migration Checklist | The required vs optional items for 4.7, tagged `[BLOCKS]` / `[TUNE]` |
|
| Opus 4.7 Migration Checklist | The required vs optional items for 4.7, tagged `[BLOCKS]` / `[TUNE]` |
|
||||||
|
| Migrating to Opus 4.8 | Migrating to Opus 4.8 (no new breaking changes; mid-session system prompts; behavioral re-tuning) |
|
||||||
|
| Opus 4.8 Migration Checklist | The required vs optional items for 4.8, tagged `[BLOCKS]` / `[TUNE]` |
|
||||||
| Verify the Migration | After edits — runtime spot-check |
|
| Verify the Migration | After edits — runtime spot-check |
|
||||||
|
|
||||||
**TL;DR:** Change the model ID string. If you were using `budget_tokens`, switch to `thinking: {type: "adaptive"}`. If you were using assistant prefills, they 400 on both Opus 4.6 and Sonnet 4.6 — switch to one of the prefill replacements (most often `output_config.format`; see the table in Breaking Changes by Source Model). If you're moving from Sonnet 4.5 to Sonnet 4.6, set `effort` explicitly — 4.6 defaults to `high`. Remove the `effort-2025-11-24` and `fine-grained-tool-streaming-2025-05-14` beta headers (GA on 4.6); remove `interleaved-thinking-2025-05-14` once you're on adaptive thinking (keep it only while using the transitional `budget_tokens` escape hatch). Then drop back from `client.beta.messages.create` to `client.messages.create`. Dial back any aggressive "CRITICAL: YOU MUST" tool instructions; 4.6 follows the system prompt much more closely.
|
**TL;DR:** Change the model ID string. If you were using `budget_tokens`, switch to `thinking: {type: "adaptive"}`. If you were using assistant prefills, they 400 on both Opus 4.6 and Sonnet 4.6 — switch to one of the prefill replacements (most often `output_config.format`; see the table in Breaking Changes by Source Model). If you're moving from Sonnet 4.5 to Sonnet 4.6, set `effort` explicitly — 4.6 defaults to `high`. Remove the `effort-2025-11-24` and `fine-grained-tool-streaming-2025-05-14` beta headers (GA on 4.6); remove `interleaved-thinking-2025-05-14` once you're on adaptive thinking (keep it only while using the transitional `budget_tokens` escape hatch). Then drop back from `client.beta.messages.create` to `client.messages.create`. Dial back any aggressive "CRITICAL: YOU MUST" tool instructions; 4.6 follows the system prompt much more closely.
|
||||||
@@ -173,12 +175,13 @@ If you're applying several prompt-tuning edits at once, offer them as a short li
|
|||||||
|
|
||||||
| If you're on… | Migrate to | Why |
|
| If you're on… | Migrate to | Why |
|
||||||
| ------------------------------------- | ------------------ | ------------------------------------------------- |
|
| ------------------------------------- | ------------------ | ------------------------------------------------- |
|
||||||
| Opus 4.6 | `claude-opus-4-7` | Most capable model; adaptive thinking only; high-res vision; see Migrating to Opus 4.7 |
|
| Opus 4.7 | `claude-opus-4-8` | Most capable model; same API surface as 4.7 (no new breaking changes) — mostly prompt re-tuning; see Migrating to Opus 4.8 |
|
||||||
| Opus 4.0 / 4.1 / 4.5 / Opus 3 | `claude-opus-4-6` | Most intelligent 4.x before 4.7; adaptive thinking; 128K output |
|
| Opus 4.6 | `claude-opus-4-8` | Apply the Opus 4.7 breaking changes, then the 4.8 re-tuning |
|
||||||
|
| Opus 4.0 / 4.1 / 4.5 / Opus 3 | `claude-opus-4-8` | Apply 4.6 → 4.7 → 4.8 in order (adaptive thinking, drop sampling params, then re-tune) |
|
||||||
| Sonnet 4.0 / 4.5 / 3.7 / 3.5 | `claude-sonnet-4-6`| Best speed / intelligence balance; adaptive thinking; 64K output |
|
| Sonnet 4.0 / 4.5 / 3.7 / 3.5 | `claude-sonnet-4-6`| Best speed / intelligence balance; adaptive thinking; 64K output |
|
||||||
| Haiku 3 / 3.5 | `claude-haiku-4-5` | Fastest and most cost-effective |
|
| Haiku 3 / 3.5 | `claude-haiku-4-5` | Fastest and most cost-effective |
|
||||||
|
|
||||||
Default to the latest Opus for the caller's tier unless they explicitly chose otherwise. If you're moving from Opus 4.5 or older directly to Opus 4.7, apply the 4.6 migration first, then layer the Opus 4.7 changes on top (see Migrating to Opus 4.7 below).
|
Default to the latest Opus for the caller's tier unless they explicitly chose otherwise. The Opus migrations layer: if you're on Opus 4.6 or older, apply each version's section in order up to your target (e.g. 4.5 → 4.8 means the 4.6, 4.7, and 4.8 sections in sequence). A 4.7 → 4.8 move has no new breaking changes — see Migrating to Opus 4.8 below.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -190,7 +193,7 @@ These models return 404 — update immediately:
|
|||||||
| ----------------------------- | ------------- | -------------------- |
|
| ----------------------------- | ------------- | -------------------- |
|
||||||
| `claude-3-7-sonnet-20250219` | Feb 19, 2026 | `claude-sonnet-4-6` |
|
| `claude-3-7-sonnet-20250219` | Feb 19, 2026 | `claude-sonnet-4-6` |
|
||||||
| `claude-3-5-haiku-20241022` | Feb 19, 2026 | `claude-haiku-4-5` |
|
| `claude-3-5-haiku-20241022` | Feb 19, 2026 | `claude-haiku-4-5` |
|
||||||
| `claude-3-opus-20240229` | Jan 5, 2026 | `claude-opus-4-7` |
|
| `claude-3-opus-20240229` | Jan 5, 2026 | `claude-opus-4-8` |
|
||||||
| `claude-3-5-sonnet-20241022` | Oct 28, 2025 | `claude-sonnet-4-6` |
|
| `claude-3-5-sonnet-20241022` | Oct 28, 2025 | `claude-sonnet-4-6` |
|
||||||
| `claude-3-5-sonnet-20240620` | Oct 28, 2025 | `claude-sonnet-4-6` |
|
| `claude-3-5-sonnet-20240620` | Oct 28, 2025 | `claude-sonnet-4-6` |
|
||||||
| `claude-3-sonnet-20240229` | Jul 21, 2025 | `claude-sonnet-4-6` |
|
| `claude-3-sonnet-20240229` | Jul 21, 2025 | `claude-sonnet-4-6` |
|
||||||
@@ -201,7 +204,7 @@ These models return 404 — update immediately:
|
|||||||
| Model | Retires | Replacement |
|
| Model | Retires | Replacement |
|
||||||
| ----------------------------- | ------------- | -------------------- |
|
| ----------------------------- | ------------- | -------------------- |
|
||||||
| `claude-3-haiku-20240307` | Apr 19, 2026 | `claude-haiku-4-5` |
|
| `claude-3-haiku-20240307` | Apr 19, 2026 | `claude-haiku-4-5` |
|
||||||
| `claude-opus-4-20250514` | June 15, 2026 | `claude-opus-4-7` |
|
| `claude-opus-4-20250514` | June 15, 2026 | `claude-opus-4-8` |
|
||||||
| `claude-sonnet-4-20250514` | June 15, 2026 | `claude-sonnet-4-6` |
|
| `claude-sonnet-4-20250514` | June 15, 2026 | `claude-sonnet-4-6` |
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -470,14 +473,15 @@ If the model is now overtriggering a tool or skill, the fix is almost always to
|
|||||||
|
|
||||||
| Old string (migration source) | New string |
|
| Old string (migration source) | New string |
|
||||||
| ------------------------------ | ------------------ |
|
| ------------------------------ | ------------------ |
|
||||||
| `claude-opus-4-6` | `claude-opus-4-7` |
|
| `claude-opus-4-7` | `claude-opus-4-8` |
|
||||||
| `claude-opus-4-5` | `claude-opus-4-7` |
|
| `claude-opus-4-6` | `claude-opus-4-8` |
|
||||||
| `claude-opus-4-1` | `claude-opus-4-7` |
|
| `claude-opus-4-5` | `claude-opus-4-8` |
|
||||||
| `claude-opus-4-0` | `claude-opus-4-7` |
|
| `claude-opus-4-1` | `claude-opus-4-8` |
|
||||||
|
| `claude-opus-4-0` | `claude-opus-4-8` |
|
||||||
| `claude-sonnet-4-5` | `claude-sonnet-4-6`|
|
| `claude-sonnet-4-5` | `claude-sonnet-4-6`|
|
||||||
| `claude-sonnet-4-0` | `claude-sonnet-4-6`|
|
| `claude-sonnet-4-0` | `claude-sonnet-4-6`|
|
||||||
|
|
||||||
Older aliases (`claude-opus-4-5`, `claude-sonnet-4-5`, `claude-opus-4-1`, etc.) are still active and can be pinned if you need time before upgrading — see `shared/models.md` for the full legacy list.
|
Older aliases (`claude-opus-4-7`, `claude-opus-4-6`, `claude-opus-4-5`, `claude-sonnet-4-5`, etc.) are still active and can be pinned if you need time before upgrading — see `shared/models.md` for the full legacy list.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -519,7 +523,7 @@ For cached prompts: the render order and hash inputs did not change, so existing
|
|||||||
|
|
||||||
> **Model ID `claude-opus-4-7` is authoritative as written here.** When the user asks to migrate to Opus 4.7, write `model="claude-opus-4-7"` exactly. Do **not** WebFetch to verify — this guide is the source of truth for migration target IDs. The corresponding entry exists in `shared/models.md`.
|
> **Model ID `claude-opus-4-7` is authoritative as written here.** When the user asks to migrate to Opus 4.7, write `model="claude-opus-4-7"` exactly. Do **not** WebFetch to verify — this guide is the source of truth for migration target IDs. The corresponding entry exists in `shared/models.md`.
|
||||||
|
|
||||||
Claude Opus 4.7 is our most capable generally available model to date. It is highly autonomous and performs exceptionally well on long-horizon agentic work, knowledge work, vision tasks, and memory tasks. This section summarizes everything new at launch. It is layered on top of the 4.6 migration above — if the caller is jumping from Opus 4.5 or older, apply the 4.6 changes first, then apply this section.
|
Claude Opus 4.7 was Anthropic's most capable model at its launch and is now the previous-generation Opus (Opus 4.8 is current — see Migrating to Opus 4.8 below). It is highly autonomous and performs exceptionally well on long-horizon agentic work, knowledge work, vision tasks, and memory tasks. This section summarizes everything that was new at the 4.7 launch and remains the layered breaking-change path for callers coming from Opus 4.6 or older. It is layered on top of the 4.6 migration above — if the caller is jumping from Opus 4.5 or older, apply the 4.6 changes first, then this section, then the 4.8 section.
|
||||||
|
|
||||||
**TL;DR for someone already on Opus 4.6:** update the model ID to `claude-opus-4-7`, strip any remaining `budget_tokens` and sampling parameters (both 400 on Opus 4.7), give `max_tokens` extra headroom and re-baseline with `count_tokens()` against the new model, opt back into `thinking.display: "summarized"` if reasoning is surfaced to users, and re-tune `effort` — it matters more on 4.7 than on any prior Opus.
|
**TL;DR for someone already on Opus 4.6:** update the model ID to `claude-opus-4-7`, strip any remaining `budget_tokens` and sampling parameters (both 400 on Opus 4.7), give `max_tokens` extra headroom and re-baseline with `count_tokens()` against the new model, opt back into `thinking.display: "summarized"` if reasoning is surfaced to users, and re-tune `effort` — it matters more on 4.7 than on any prior Opus.
|
||||||
|
|
||||||
@@ -758,12 +762,108 @@ Every item is tagged: **`[BLOCKS]`** items cause a 400 error, infinite loop, sil
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Verify the Migration
|
## Migrating to Opus 4.8
|
||||||
|
|
||||||
After updating, spot-check that the new model is actually being used. Replace `YOUR_TARGET_MODEL` with the model string you migrated to (e.g. `claude-opus-4-7`, `claude-opus-4-6`, `claude-sonnet-4-6`, `claude-haiku-4-5`) and keep the assertion prefix in sync:
|
> **Model ID `claude-opus-4-8` is authoritative as written here.** When the user asks to migrate to Opus 4.8, write `model="claude-opus-4-8"` exactly. Do **not** WebFetch to verify — this guide is the source of truth for migration target IDs. The corresponding entry exists in `shared/models.md`.
|
||||||
|
|
||||||
|
Claude Opus 4.8 is our most capable generally available model to date — highly autonomous, with state-of-the-art long-horizon agentic execution, knowledge work, and memory. It is layered on top of the Opus 4.7 migration above. If the caller is jumping from Opus 4.6 or older, apply the 4.6 and 4.7 sections first, then this one.
|
||||||
|
|
||||||
|
**No new breaking changes.** Opus 4.8 keeps the same request surface as Opus 4.7. The same calls that already work on 4.7 work unchanged on 4.8 — adaptive thinking only (`thinking: {type: "enabled", budget_tokens: N}` still 400s; use `{type: "adaptive"}`), sampling parameters (`temperature`, `top_p`, `top_k`) still rejected, last-assistant-turn prefills still 400, `thinking.display` still defaults to `"omitted"`, and the `low`/`medium`/`high`/`xhigh`/`max` effort levels, Task Budgets (beta), and high-resolution vision all behave as on 4.7. A 4.7 → 4.8 migration is therefore **the model-ID swap plus prompt re-tuning** — there is no required code edit beyond the model string.
|
||||||
|
|
||||||
|
**TL;DR for someone already on Opus 4.7:** swap the model ID to `claude-opus-4-8`. Nothing else is required to avoid an error. Then re-tune prompts for the behavioral shifts: 4.8 narrates *more* than 4.7 (add a silence-default if you want 4.7-like terseness), writes in a warmer, less hedged voice, is more deliberate and asks more often (add autonomy guidance to claw back ask-rate), and is more conservative about reaching for search, subagents, file-based memory, and custom tools (add explicit "when to use this" triggering). For long-horizon agentic work, give the full task specification up front in one well-specified turn and run at high effort.
|
||||||
|
|
||||||
|
### No new API breaking changes (inherited from 4.7)
|
||||||
|
|
||||||
|
These all carry over from Opus 4.7 unchanged — apply them only if the caller is coming from Opus 4.6 or earlier (see the **Migrating to Opus 4.7** section above for the before/after and the SDK-specific syntax):
|
||||||
|
|
||||||
|
- `thinking: {type: "enabled", budget_tokens: N}` → 400. Use `thinking: {type: "adaptive"}` + `output_config.effort`.
|
||||||
|
- `temperature`, `top_p`, `top_k` → 400. Remove them; steer with prompting.
|
||||||
|
- Last-assistant-turn prefills → 400. Use `output_config.format` (structured outputs) or a system-prompt instruction.
|
||||||
|
- `thinking.display` defaults to `"omitted"`; set `"summarized"` if you surface reasoning to users.
|
||||||
|
|
||||||
|
If the caller is already on Opus 4.7 and these are clean, there is nothing to change here.
|
||||||
|
|
||||||
|
### New API feature: mid-session system prompts
|
||||||
|
|
||||||
|
You can deliver trusted instructions partway through a session by placing `{"role": "system", ...}` entries directly in the `messages` array — without editing the top-level system prompt and invalidating your prompt cache. Use it for things the application learns mid-session: the user delivered async context, a mode toggled (auto-approve enabled), files changed on disk, the remaining token budget dropped.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
YOUR_TARGET_MODEL = "claude-opus-4-7" # or "claude-opus-4-6", "claude-sonnet-4-6", "claude-haiku-4-5"
|
messages=[
|
||||||
|
{"role": "user", "content": [{"type": "tool_result", "tool_use_id": "...", "content": "..."}]},
|
||||||
|
{"role": "system", "content": "This project's codebase is Go. Write code in Go."},
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Phrase these as **context, not commands**. State the fact and let Claude act on it; avoid override-style language ("ignore what the user said", "regardless of the user's request", "disregard the previous instruction"). Claude is trained to protect users from instructions that appear to work against them, and that protection applies to the system role too. This is a beta (`anthropic-beta: mid-conversation-system-2026-04-07`) and is available from Opus 4.7 onward, not 4.8-exclusive. For cache-placement details and the older-model `<system-reminder>` fallback, see `shared/prompt-caching.md` and `shared/agent-design.md`.
|
||||||
|
|
||||||
|
### Capability improvements
|
||||||
|
|
||||||
|
**Long-horizon agentic execution.** Opus 4.8 is state-of-the-art at long, autonomous agentic work — complex refactors and overnight coding runs that complete without human correction. To get the most out of it, **give the full task specification up front in a single well-specified initial turn and run at high effort** (`effort: "high"` or `"xhigh"`). Its long-horizon coherence comes partly from reasoning more at each step; combined with a clear up-front goal, that more-intelligent planning often produces more efficient *and* more accurate output than prior frontier models. The "clear goal up front" principle maps to two product surfaces: in Claude Code, `/goal` sets direction for the run; with **Managed Agents (CMA)**, state what "done" looks like via an **Outcome** (`user.define_outcome` with a gradeable rubric — the harness runs an iterate → grade → revise loop), see `shared/managed-agents-outcomes.md`.
|
||||||
|
|
||||||
|
**Effort is a dimension to test, not a fixed setting.** On prior models many reached for `xhigh` reflexively to maximize intelligence. Opus 4.8 has a higher intelligence ceiling, so **start at `high` as the default and iterate** rather than defaulting to `xhigh`. Sweep `medium`, `high`, and `xhigh` on your own eval set and weigh the intelligence ↔ latency ↔ cost tradeoff per route — the relationship isn't monotonic: higher effort up front often *reduces* turn count and total cost on agentic work, while for some tasks `medium` delivers equally good results in less time. Reserve `max` for extremely hard, latency-insensitive cases. The per-level effort table in the **Migrating to Opus 4.7** section above applies unchanged on 4.8.
|
||||||
|
|
||||||
|
**Writing voice and clarity.** Testers consistently describe 4.8's prose as clearer, warmer, and less hedged than prior models, with fewer measurable AI vocal tics — especially at higher effort, where it approaches expert-level prose and structure. This is roughly the **opposite** direction from the 4.7 shift (4.7 was more clipped, direct, and less validation-forward). If you added style prompts to counter 4.7's terseness or to inject warmth, re-evaluate them against the new baseline before keeping them — they may now overcorrect. 4.8 is also a stronger thought partner: more thoughtful, more willing to push back, and more likely to infer the right answer from context.
|
||||||
|
|
||||||
|
**Code review and debugging.** Stronger real-bug finding and clearer explanations than 4.7 — one-shot fixes where 4.7 needed more, and correctly identifying intermittent flakes rather than declaring "fixed" after one clean run. The 4.7 caveat still applies: if a review harness says "only report high-severity issues" or "be conservative", 4.8 follows it literally and measured recall can drop even though underlying bug-finding improved. Tell the model to report everything and filter downstream (or review a second time) — see the **Code review** guidance in the 4.7 section for the recommended prompt.
|
||||||
|
|
||||||
|
### Behavioral shifts (prompt-tunable)
|
||||||
|
|
||||||
|
None of these break code, but prompts tuned for Opus 4.7 may land differently. 4.8 follows instructions well, so small, explicit nudges close the gap.
|
||||||
|
|
||||||
|
**Tool triggering is surface-dependent (search & knowledge).** 4.8's tool-triggering is more surface-dependent than in prior models: with a system prompt present it is high-precision / low-recall — web search triggers slightly more often but runs fewer rounds per trigger, while knowledge-retrieval tools (Drive, project knowledge, connected files) trigger *less* often. It searches when it's confident search is needed and otherwise answers from context, which can lower research depth on tasks that need it. Recover should-search rate with an explicit search-first instruction:
|
||||||
|
|
||||||
|
> ```
|
||||||
|
> <search_first>
|
||||||
|
> For questions where current information would change the answer (recent events, current roles or prices, version-specific behavior, or anything the user flags as time-sensitive) search before answering rather than answering from memory. For open-ended research requests, begin searching immediately; do not ask a scoping question first unless the request is genuinely ambiguous about what to research.
|
||||||
|
> </search_first>
|
||||||
|
> ```
|
||||||
|
|
||||||
|
**Under-utilization of subagents, memory, and custom tools.** Separately from search, 4.8 is conservative about reaching for capabilities that need an explicit "decide to use this" step — file-based memory, subagent delegation, custom tools. It won't reach for complex or expensive capabilities unless reasonably sure they're needed. This is steerable since 4.8 follows instructions well — say *when* each capability applies, not just that it exists:
|
||||||
|
|
||||||
|
> *"Before any task longer than a few turns, check your memory file for relevant prior context and write new findings to it as you go. When a task fans out across independent items (many files to read, many tests to run, many candidates to check), delegate to subagents rather than iterating serially."*
|
||||||
|
|
||||||
|
The same lever works at the **tool-description** level, not just the system prompt: prescriptive descriptions that state *when* to call a tool (e.g. "Call this when the user asks about current prices or recent events") give meaningful lift on 4.8 over descriptions that only state what the tool does. Make the trigger condition part of each capability's own `description`.
|
||||||
|
|
||||||
|
**More user-facing narration.** 4.8 narrates more than 4.7 — more text between tool calls in long tool-calling sessions, and longer, more detailed end-of-task wrap-ups by default. If you previously added scaffolding to force interim status ("after every 3 tool calls, summarize progress"), **remove it** — 4.8 does this on its own. If the narration is too verbose for a coding agent, an explicit silence-default makes it behave like 4.7 with no loss of quality:
|
||||||
|
|
||||||
|
> *"Default to silence between tool calls. Only write text when you find something, change direction, or hit a blocker — one sentence each. Do not narrate routine actions ('Now I'll...', 'Let me check...', 'Looking at...'). When done: one or two sentences on the outcome. Do not recap every file or test — the user has been following along."*
|
||||||
|
|
||||||
|
For knowledge-work deliverables (reports, analysis readouts), verbosity responds very well to instructions in user preferences or the user turn — expose a verbosity preference rather than hard-coding a length.
|
||||||
|
|
||||||
|
**More deliberate — asks more often.** 4.8 is more deliberate than prior Opus models. On minor decisions it would previously just make (a variable name, a default value, which of two equivalent approaches), it tends to pause and ask, and it often closes a completed task with "Want me to also…?" rather than doing the obvious next step or stopping cleanly. This is preferred for high-stakes or unfamiliar codebases, but bugs users when uncalibrated. Grant autonomy on the small stuff while keeping caution where it matters (in Claude Code testing this cut ask-rate by ~12 percentage points with no increase in over-reach):
|
||||||
|
|
||||||
|
> *"For minor choices (naming, formatting, default values, which approach among equivalents), pick a reasonable option and note it rather than asking. For scope changes or destructive actions, still ask first."*
|
||||||
|
|
||||||
|
**Verbose reasoning when thinking is disabled.** With `thinking: {type: "disabled"}`, 4.8 occasionally writes longer explanations of its reasoning into the visible response, which reads as verbose when the user wants a fast, quick answer. The simplest fix is to leave adaptive thinking on — set `thinking: {type: "adaptive"}` (the recommended setting; it adjusts how much to think per task). Note adaptive is **not** on when the field is omitted — like Opus 4.7, a request with no `thinking` field runs without thinking, so set it explicitly. If you need thinking off for latency or cost, scope it in the system prompt:
|
||||||
|
|
||||||
|
> *"Respond only with your final answer. Do not include exploratory reasoning, intermediate drafts, diffs you considered but rejected, or meta-commentary about your process."*
|
||||||
|
|
||||||
|
### Opus 4.8 Migration Checklist
|
||||||
|
|
||||||
|
Every item is tagged: **`[BLOCKS]`** items cause a 400 error if missed; **`[TUNE]`** items are quality/cost adjustments — surface them to the user as recommendations.
|
||||||
|
|
||||||
|
For a caller **already on Opus 4.7**, only the first item is required; everything else is `[TUNE]`. The conditional `[BLOCKS]` item applies only when coming from Opus 4.6 or earlier.
|
||||||
|
|
||||||
|
- [ ] **[BLOCKS]** Update the `model=` string to `claude-opus-4-8`
|
||||||
|
- [ ] **[BLOCKS]** *(only if coming from Opus 4.6 or earlier)* Apply the **Migrating to Opus 4.7** breaking changes first — `budget_tokens` → adaptive thinking, strip `temperature`/`top_p`/`top_k`, remove last-assistant-turn prefills. These already 400 on 4.7 and continue to 400 on 4.8.
|
||||||
|
- [ ] **[TUNE]** Long-horizon / agentic work: put the full task spec in one well-specified first turn and run at `high` or `xhigh` effort (Claude Code: `/goal`; Managed Agents: an Outcome with a gradeable rubric)
|
||||||
|
- [ ] **[TUNE]** Effort: sweep `medium` / `high` / `xhigh` on your eval set and pick per route by the intelligence ↔ latency ↔ cost tradeoff (default `high`, `xhigh` for coding/agentic)
|
||||||
|
- [ ] **[TUNE]** Research depth & tool use: add a search-first instruction; add explicit triggering guidance for subagents, file-based memory, and custom tools (4.8 under-reaches for these by default) — in the system prompt *and* in each tool's own `description` (prescriptive "call this when…" descriptions give measurable lift)
|
||||||
|
- [ ] **[TUNE]** Narration: remove forced-progress scaffolding (*"after every N tool calls…"*); add a silence-default if a coding agent is too chatty
|
||||||
|
- [ ] **[TUNE]** Autonomy: add small-decisions-don't-ask guidance to cut ask-rate, while keeping caution on scope changes / destructive actions
|
||||||
|
- [ ] **[TUNE]** Writing voice: re-evaluate style prompts added to counter 4.7's directness — 4.8 is warmer and less hedged by default; re-baseline before keeping them
|
||||||
|
- [ ] **[TUNE]** Code-review harnesses: keep the report-everything-filter-downstream pattern (4.8 follows "only high-severity" / "be conservative" filters literally, which can depress measured recall)
|
||||||
|
- [ ] **[TUNE]** Thinking-disabled paths: add a final-answer-only instruction if reasoning leaks into the visible response
|
||||||
|
- [ ] **[TUNE]** Consider mid-session system messages (`role:"system"` in `messages`, beta `mid-conversation-system-2026-04-07`) for context the app learns mid-session, instead of rebuilding the top-level system prompt and invalidating the cache
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Verify the Migration
|
||||||
|
|
||||||
|
After updating, spot-check that the new model is actually being used. Replace `YOUR_TARGET_MODEL` with the model string you migrated to (e.g. `claude-opus-4-8`, `claude-opus-4-7`, `claude-sonnet-4-6`, `claude-haiku-4-5`) and keep the assertion prefix in sync:
|
||||||
|
|
||||||
|
```python
|
||||||
|
YOUR_TARGET_MODEL = "claude-opus-4-8" # or "claude-opus-4-7", "claude-sonnet-4-6", "claude-haiku-4-5"
|
||||||
response = client.messages.create(model=YOUR_TARGET_MODEL, max_tokens=64, messages=[...])
|
response = client.messages.create(model=YOUR_TARGET_MODEL, max_tokens=64, messages=[...])
|
||||||
assert response.model.startswith(YOUR_TARGET_MODEL), response.model
|
assert response.model.startswith(YOUR_TARGET_MODEL), response.model
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
For **live** capability data — context window, max output tokens, feature support (thinking, vision, effort, structured outputs, etc.) — query the Models API instead of relying on the cached tables below. Use this when the user asks "what's the context window for X", "does model X support vision/thinking/effort", "which models support feature Y", or wants to select a model by capability at runtime.
|
For **live** capability data — context window, max output tokens, feature support (thinking, vision, effort, structured outputs, etc.) — query the Models API instead of relying on the cached tables below. Use this when the user asks "what's the context window for X", "does model X support vision/thinking/effort", "which models support feature Y", or wants to select a model by capability at runtime.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
m = client.models.retrieve("claude-opus-4-7")
|
m = client.models.retrieve("claude-opus-4-8")
|
||||||
m.id # "claude-opus-4-7"
|
m.id # "claude-opus-4-8"
|
||||||
m.display_name # "Claude Opus 4.7"
|
m.display_name # "Claude Opus 4.8"
|
||||||
m.max_input_tokens # context window (int)
|
m.max_input_tokens # context window (int)
|
||||||
m.max_tokens # max output tokens (int)
|
m.max_tokens # max output tokens (int)
|
||||||
|
|
||||||
@@ -32,16 +32,16 @@ Top-level fields (`id`, `display_name`, `max_input_tokens`, `max_tokens`) are ty
|
|||||||
### Raw HTTP
|
### Raw HTTP
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl https://api.anthropic.com/v1/models/claude-opus-4-7 \
|
curl https://api.anthropic.com/v1/models/claude-opus-4-8 \
|
||||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||||
-H "anthropic-version: 2023-06-01"
|
-H "anthropic-version: 2023-06-01"
|
||||||
```
|
```
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"id": "claude-opus-4-7",
|
"id": "claude-opus-4-8",
|
||||||
"display_name": "Claude Opus 4.7",
|
"display_name": "Claude Opus 4.8",
|
||||||
"max_input_tokens": 200000,
|
"max_input_tokens": 1000000,
|
||||||
"max_tokens": 128000,
|
"max_tokens": 128000,
|
||||||
"capabilities": {
|
"capabilities": {
|
||||||
"image_input": {"supported": true},
|
"image_input": {"supported": true},
|
||||||
@@ -57,14 +57,16 @@ curl https://api.anthropic.com/v1/models/claude-opus-4-7 \
|
|||||||
|
|
||||||
| Friendly Name | Alias (use this) | Full ID | Context | Max Output | Status |
|
| Friendly Name | Alias (use this) | Full ID | Context | Max Output | Status |
|
||||||
|-------------------|---------------------|-------------------------------|----------------|------------|--------|
|
|-------------------|---------------------|-------------------------------|----------------|------------|--------|
|
||||||
|
| Claude Opus 4.8 | `claude-opus-4-8` | — | 1M | 128K | Active |
|
||||||
| Claude Opus 4.7 | `claude-opus-4-7` | — | 1M | 128K | Active |
|
| Claude Opus 4.7 | `claude-opus-4-7` | — | 1M | 128K | Active |
|
||||||
| Claude Opus 4.6 | `claude-opus-4-6` | — | 1M | 128K | Active |
|
| Claude Opus 4.6 | `claude-opus-4-6` | — | 1M | 128K | Active |
|
||||||
| Claude Sonnet 4.6 | `claude-sonnet-4-6` | - | 1M | 64K | Active |
|
| Claude Sonnet 4.6 | `claude-sonnet-4-6` | - | 1M | 64K | Active |
|
||||||
| Claude Haiku 4.5 | `claude-haiku-4-5` | `claude-haiku-4-5-20251001` | 200K | 64K | Active |
|
| Claude Haiku 4.5 | `claude-haiku-4-5` | `claude-haiku-4-5-20251001` | 200K | 64K | Active |
|
||||||
|
|
||||||
### Model Descriptions
|
### Model Descriptions
|
||||||
- **Claude Opus 4.7** — The most capable Claude model to date — highly autonomous, strong on long-horizon agentic work, knowledge work, vision, and memory. Adaptive thinking only; sampling parameters and `budget_tokens` are removed. 1M context window at standard API pricing (no long-context premium) — see `shared/model-migration.md` → Migrating to Opus 4.7 for breaking changes.
|
- **Claude Opus 4.8** — The most capable Claude model to date — highly autonomous, state-of-the-art on long-horizon agentic work, knowledge work, and memory; clearer, warmer writing. Same API surface as Opus 4.7 (adaptive thinking only; sampling parameters and `budget_tokens` removed). 1M context window at standard API pricing (no long-context premium). See `shared/model-migration.md` → Migrating to Opus 4.8 — a 4.7 → 4.8 move is a model-ID swap plus prompt re-tuning, no new breaking changes.
|
||||||
- **Claude Opus 4.6** — Previous-generation Opus. Supports adaptive thinking (recommended), 128K max output tokens (requires streaming for large outputs). 1M context window.
|
- **Claude Opus 4.7** — Previous-generation Opus. Highly autonomous; strong on long-horizon agentic work, knowledge work, vision, and memory. Adaptive thinking only; sampling parameters and `budget_tokens` removed. 1M context window. See `shared/model-migration.md` → Migrating to Opus 4.7.
|
||||||
|
- **Claude Opus 4.6** — Older Opus. Supports adaptive thinking (recommended), 128K max output tokens (requires streaming for large outputs). 1M context window.
|
||||||
- **Claude Sonnet 4.6** — Our best combination of speed and intelligence. Supports adaptive thinking (recommended). 1M context window. 64K max output tokens.
|
- **Claude Sonnet 4.6** — Our best combination of speed and intelligence. Supports adaptive thinking (recommended). 1M context window. 64K max output tokens.
|
||||||
- **Claude Haiku 4.5** — Fastest and most cost-effective model for simple tasks.
|
- **Claude Haiku 4.5** — Fastest and most cost-effective model for simple tasks.
|
||||||
|
|
||||||
@@ -103,12 +105,13 @@ When a user asks for a model by name, use this table to find the correct model I
|
|||||||
|
|
||||||
| User says... | Use this model ID |
|
| User says... | Use this model ID |
|
||||||
|-------------------------------------------|--------------------------------|
|
|-------------------------------------------|--------------------------------|
|
||||||
| "opus", "most powerful" | `claude-opus-4-7` |
|
| "opus", "most powerful" | `claude-opus-4-8` |
|
||||||
|
| "opus 4.8" | `claude-opus-4-8` |
|
||||||
| "opus 4.7" | `claude-opus-4-7` |
|
| "opus 4.7" | `claude-opus-4-7` |
|
||||||
| "opus 4.6" | `claude-opus-4-6` |
|
| "opus 4.6" | `claude-opus-4-6` |
|
||||||
| "opus 4.5" | `claude-opus-4-5` |
|
| "opus 4.5" | `claude-opus-4-5` |
|
||||||
| "opus 4.1" | `claude-opus-4-1` |
|
| "opus 4.1" | `claude-opus-4-1` |
|
||||||
| "opus 4", "opus 4.0" | `claude-opus-4-0` |
|
| "opus 4", "opus 4.0" | `claude-opus-4-0` (deprecated — suggest `claude-opus-4-8`) |
|
||||||
| "sonnet", "balanced" | `claude-sonnet-4-6` |
|
| "sonnet", "balanced" | `claude-sonnet-4-6` |
|
||||||
| "sonnet 4.6" | `claude-sonnet-4-6` |
|
| "sonnet 4.6" | `claude-sonnet-4-6` |
|
||||||
| "sonnet 4.5" | `claude-sonnet-4-5` |
|
| "sonnet 4.5" | `claude-sonnet-4-5` |
|
||||||
|
|||||||
@@ -111,11 +111,11 @@ Fix by moving the dynamic piece after the last breakpoint, making it determinist
|
|||||||
|
|
||||||
| Model | Minimum |
|
| Model | Minimum |
|
||||||
|---|---:|
|
|---|---:|
|
||||||
| Opus 4.7, Opus 4.6, Opus 4.5, Haiku 4.5 | 4096 tokens |
|
| Opus 4.8, Opus 4.7, Opus 4.6, Opus 4.5, Haiku 4.5 | 4096 tokens |
|
||||||
| Sonnet 4.6, Haiku 3.5, Haiku 3 | 2048 tokens |
|
| Sonnet 4.6, Haiku 3.5, Haiku 3 | 2048 tokens |
|
||||||
| Sonnet 4.5, Sonnet 4.1, Sonnet 4, Sonnet 3.7 | 1024 tokens |
|
| Sonnet 4.5, Sonnet 4.1, Sonnet 4, Sonnet 3.7 | 1024 tokens |
|
||||||
|
|
||||||
A 3K-token prompt caches on Sonnet 4.5 but silently won't on Opus 4.7.
|
A 3K-token prompt caches on Sonnet 4.5 but silently won't on Opus 4.8.
|
||||||
|
|
||||||
**Economics:** Cache reads cost ~0.1× base input price. Cache writes cost **1.25× for 5-minute TTL, 2× for 1-hour TTL**. Break-even depends on TTL: with 5-minute TTL, two requests break even (1.25× + 0.1× = 1.35× vs 2× uncached); with 1-hour TTL, you need at least three requests (2× + 0.2× = 2.2× vs 3× uncached). The 1-hour TTL keeps entries alive across gaps in bursty traffic, but the doubled write cost means it needs more reads to pay off.
|
**Economics:** Cache reads cost ~0.1× base input price. Cache writes cost **1.25× for 5-minute TTL, 2× for 1-hour TTL**. Break-even depends on TTL: with 5-minute TTL, two requests break even (1.25× + 0.1× = 1.35× vs 2× uncached); with 1-hour TTL, you need at least three requests (2× + 0.2× = 2.2× vs 3× uncached). The 1-hour TTL keeps entries alive across gaps in bursty traffic, but the doubled write cost means it needs more reads to pay off.
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ Each tool requires a name, description, and JSON Schema for its inputs:
|
|||||||
**Best practices for tool definitions:**
|
**Best practices for tool definitions:**
|
||||||
|
|
||||||
- Use clear, descriptive names (e.g., `get_weather`, `search_database`, `send_email`)
|
- Use clear, descriptive names (e.g., `get_weather`, `search_database`, `send_email`)
|
||||||
- Write detailed descriptions — Claude uses these to decide when to use the tool
|
- Write detailed descriptions — Claude uses these to decide when to use the tool. Be **prescriptive about *when* to call it**, not just what it does (e.g. "Call this when the user asks about current prices or recent events"). On recent Opus models, which reach for tools more conservatively, trigger conditions in the description give measurable lift in should-call rate.
|
||||||
- Include descriptions for each property
|
- Include descriptions for each property
|
||||||
- Use `enum` for parameters with a fixed set of values
|
- Use `enum` for parameters with a fixed set of values
|
||||||
- Mark truly required parameters in `required`; make others optional with defaults
|
- Mark truly required parameters in `required`; make others optional with defaults
|
||||||
@@ -74,7 +74,7 @@ if response.stop_reason == "pause_turn":
|
|||||||
]
|
]
|
||||||
# Make another API request — server resumes automatically
|
# Make another API request — server resumes automatically
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model="claude-opus-4-7", messages=messages, tools=tools
|
model="claude-opus-4-8", messages=messages, tools=tools
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ Web search and web fetch let Claude search the web and retrieve page content. Th
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Dynamic Filtering (Opus 4.7 / Opus 4.6 / Sonnet 4.6)
|
### Dynamic Filtering (Opus 4.8 / Opus 4.7 / Opus 4.6 / Sonnet 4.6)
|
||||||
|
|
||||||
The `web_search_20260209` and `web_fetch_20260209` versions support **dynamic filtering** — Claude writes and executes code to filter search results before they reach the context window, improving accuracy and token efficiency. Dynamic filtering is built into these tool versions and activates automatically; you do not need to separately declare the `code_execution` tool or pass any beta header.
|
The `web_search_20260209` and `web_fetch_20260209` versions support **dynamic filtering** — Claude writes and executes code to filter search results before they reach the context window, improving accuracy and token efficiency. Dynamic filtering is built into these tool versions and activates automatically; you do not need to separately declare the `code_execution` tool or pass any beta header.
|
||||||
|
|
||||||
@@ -280,7 +280,7 @@ Two features are available:
|
|||||||
- **JSON outputs** (`output_config.format`): Control Claude's response format
|
- **JSON outputs** (`output_config.format`): Control Claude's response format
|
||||||
- **Strict tool use** (`strict: true`): Guarantee valid tool parameter schemas
|
- **Strict tool use** (`strict: true`): Guarantee valid tool parameter schemas
|
||||||
|
|
||||||
**Supported models:** Claude Opus 4.7, Claude Sonnet 4.6, and Claude Haiku 4.5. Legacy models (Claude Opus 4.5, Claude Opus 4.1) also support structured outputs.
|
**Supported models:** Claude Opus 4.8, Claude Sonnet 4.6, and Claude Haiku 4.5. Legacy models (Claude Opus 4.5, Claude Opus 4.1) also support structured outputs.
|
||||||
|
|
||||||
> **Recommended:** Use `client.messages.parse()` which automatically validates responses against your schema. When using `messages.create()` directly, use `output_config: {format: {...}}`. The `output_format` convenience parameter is also accepted by some SDK methods (e.g., `.parse()`), but `output_config.format` is the canonical API-level parameter.
|
> **Recommended:** Use `client.messages.parse()` which automatically validates responses against your schema. When using `messages.create()` directly, use `output_config: {format: {...}}`. The `output_format` convenience parameter is also accepted by some SDK methods (e.g., `.parse()`), but `output_config.format` is the canonical API-level parameter.
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const client = new Anthropic({ apiKey: "your-api-key" });
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [{ role: "user", content: "What is the capital of France?" }],
|
messages: [{ role: "user", content: "What is the capital of France?" }],
|
||||||
});
|
});
|
||||||
@@ -43,7 +43,7 @@ for (const block of response.content) {
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
system:
|
system:
|
||||||
"You are a helpful coding assistant. Always provide examples in Python.",
|
"You are a helpful coding assistant. Always provide examples in Python.",
|
||||||
@@ -59,7 +59,7 @@ const response = await client.messages.create({
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -84,7 +84,7 @@ import fs from "fs";
|
|||||||
const imageData = fs.readFileSync("image.png").toString("base64");
|
const imageData = fs.readFileSync("image.png").toString("base64");
|
||||||
|
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -113,7 +113,7 @@ Use top-level `cache_control` to automatically cache the last cacheable block in
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
cache_control: { type: "ephemeral" }, // auto-caches the last cacheable block
|
cache_control: { type: "ephemeral" }, // auto-caches the last cacheable block
|
||||||
system: "You are an expert on this large document...",
|
system: "You are an expert on this large document...",
|
||||||
@@ -127,7 +127,7 @@ For fine-grained control, add `cache_control` to specific content blocks:
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
system: [
|
system: [
|
||||||
{
|
{
|
||||||
@@ -141,7 +141,7 @@ const response = await client.messages.create({
|
|||||||
|
|
||||||
// With explicit TTL (time-to-live)
|
// With explicit TTL (time-to-live)
|
||||||
const response2 = await client.messages.create({
|
const response2 = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
system: [
|
system: [
|
||||||
{
|
{
|
||||||
@@ -168,13 +168,13 @@ If `cache_read_input_tokens` is zero across repeated identical-prefix requests,
|
|||||||
|
|
||||||
## Extended Thinking
|
## Extended Thinking
|
||||||
|
|
||||||
> **Opus 4.7, Opus 4.6, and Sonnet 4.6:** Use adaptive thinking. `budget_tokens` is removed on Opus 4.7 (400 if sent); deprecated on Opus 4.6 and Sonnet 4.6.
|
> **Opus 4.8, Opus 4.7, Opus 4.6, and Sonnet 4.6:** Use adaptive thinking. `budget_tokens` is removed on Opus 4.8 and 4.7 (400 if sent); deprecated on Opus 4.6 and Sonnet 4.6.
|
||||||
> **Older models:** Use `thinking: {type: "enabled", budget_tokens: N}` (must be < `max_tokens`, min 1024).
|
> **Older models:** Use `thinking: {type: "enabled", budget_tokens: N}` (must be < `max_tokens`, min 1024).
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// Opus 4.7 / 4.6: adaptive thinking (recommended)
|
// Opus 4.8 / 4.7 / 4.6: adaptive thinking (recommended)
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
thinking: { type: "adaptive" },
|
thinking: { type: "adaptive" },
|
||||||
output_config: { effort: "high" }, // low | medium | high | max
|
output_config: { effort: "high" }, // low | medium | high | max
|
||||||
@@ -232,7 +232,7 @@ const messages: Anthropic.MessageParam[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: messages,
|
messages: messages,
|
||||||
});
|
});
|
||||||
@@ -248,7 +248,7 @@ const response = await client.messages.create({
|
|||||||
|
|
||||||
### Compaction (long conversations)
|
### Compaction (long conversations)
|
||||||
|
|
||||||
> **Beta, Opus 4.7, Opus 4.6, and Sonnet 4.6.** When conversations approach the 200K context window, compaction automatically summarizes earlier context server-side. The API returns a `compaction` block; you must pass it back on subsequent requests — append `response.content`, not just the text.
|
> **Beta, Opus 4.8, Opus 4.7, Opus 4.6, and Sonnet 4.6.** When conversations approach the 200K context window, compaction automatically summarizes earlier context server-side. The API returns a `compaction` block; you must pass it back on subsequent requests — append `response.content`, not just the text.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import Anthropic from "@anthropic-ai/sdk";
|
import Anthropic from "@anthropic-ai/sdk";
|
||||||
@@ -261,7 +261,7 @@ async function chat(userMessage: string): Promise<string> {
|
|||||||
|
|
||||||
const response = await client.beta.messages.create({
|
const response = await client.beta.messages.create({
|
||||||
betas: ["compact-2026-01-12"],
|
betas: ["compact-2026-01-12"],
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages,
|
messages,
|
||||||
context_management: {
|
context_management: {
|
||||||
@@ -308,7 +308,7 @@ The `stop_reason` field in the response indicates why the model stopped generati
|
|||||||
```typescript
|
```typescript
|
||||||
// Automatic caching (simplest — caches the last cacheable block)
|
// Automatic caching (simplest — caches the last cacheable block)
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
cache_control: { type: "ephemeral" },
|
cache_control: { type: "ephemeral" },
|
||||||
system: largeDocumentText, // e.g., 50KB of context
|
system: largeDocumentText, // e.g., 50KB of context
|
||||||
@@ -323,7 +323,7 @@ const response = await client.messages.create({
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const countResponse = await client.messages.countTokens({
|
const countResponse = await client.messages.countTokens({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
messages: messages,
|
messages: messages,
|
||||||
system: system,
|
system: system,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const messageBatch = await client.messages.batches.create({
|
|||||||
{
|
{
|
||||||
custom_id: "request-1",
|
custom_id: "request-1",
|
||||||
params: {
|
params: {
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{ role: "user", content: "Summarize climate change impacts" },
|
{ role: "user", content: "Summarize climate change impacts" },
|
||||||
@@ -34,7 +34,7 @@ const messageBatch = await client.messages.batches.create({
|
|||||||
{
|
{
|
||||||
custom_id: "request-2",
|
custom_id: "request-2",
|
||||||
params: {
|
params: {
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{ role: "user", content: "Explain quantum computing basics" },
|
{ role: "user", content: "Explain quantum computing basics" },
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ console.log(`Size: ${uploaded.size_bytes} bytes`);
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.beta.messages.create({
|
const response = await client.beta.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const stream = client.messages.stream({
|
const stream = client.messages.stream({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 64000,
|
max_tokens: 64000,
|
||||||
messages: [{ role: "user", content: "Write a story" }],
|
messages: [{ role: "user", content: "Write a story" }],
|
||||||
});
|
});
|
||||||
@@ -23,11 +23,11 @@ for await (const event of stream) {
|
|||||||
|
|
||||||
## Handling Different Content Types
|
## Handling Different Content Types
|
||||||
|
|
||||||
> **Opus 4.7 / Opus 4.6:** Use `thinking: {type: "adaptive"}`. On older models, use `thinking: {type: "enabled", budget_tokens: N}` instead.
|
> **Opus 4.8 / Opus 4.7 / Opus 4.6:** Use `thinking: {type: "adaptive"}`. On older models, use `thinking: {type: "enabled", budget_tokens: N}` instead.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const stream = client.messages.stream({
|
const stream = client.messages.stream({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 64000,
|
max_tokens: 64000,
|
||||||
thinking: { type: "adaptive" },
|
thinking: { type: "adaptive" },
|
||||||
messages: [{ role: "user", content: "Analyze this problem" }],
|
messages: [{ role: "user", content: "Analyze this problem" }],
|
||||||
@@ -82,7 +82,7 @@ const getWeather = betaZodTool({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const runner = client.beta.messages.toolRunner({
|
const runner = client.beta.messages.toolRunner({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 64000,
|
max_tokens: 64000,
|
||||||
tools: [getWeather],
|
tools: [getWeather],
|
||||||
messages: [
|
messages: [
|
||||||
@@ -117,7 +117,7 @@ for await (const messageStream of runner) {
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const stream = client.messages.stream({
|
const stream = client.messages.stream({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 64000,
|
max_tokens: 64000,
|
||||||
messages: [{ role: "user", content: "Hello" }],
|
messages: [{ role: "user", content: "Hello" }],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const getWeather = betaZodTool({
|
|||||||
|
|
||||||
// The tool runner handles the agentic loop and returns the final message
|
// The tool runner handles the agentic loop and returns the final message
|
||||||
const finalMessage = await client.beta.messages.toolRunner({
|
const finalMessage = await client.beta.messages.toolRunner({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
tools: [getWeather],
|
tools: [getWeather],
|
||||||
messages: [{ role: "user", content: "What's the weather in Paris?" }],
|
messages: [{ role: "user", content: "What's the weather in Paris?" }],
|
||||||
@@ -61,7 +61,7 @@ let messages: Anthropic.MessageParam[] = [{ role: "user", content: userInput }];
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
tools: tools,
|
tools: tools,
|
||||||
messages: messages,
|
messages: messages,
|
||||||
@@ -108,7 +108,7 @@ let messages: Anthropic.MessageParam[] = [{ role: "user", content: userInput }];
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const stream = client.messages.stream({
|
const stream = client.messages.stream({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 64000,
|
max_tokens: 64000,
|
||||||
tools,
|
tools,
|
||||||
messages,
|
messages,
|
||||||
@@ -163,7 +163,7 @@ while (true) {
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
tools: tools,
|
tools: tools,
|
||||||
messages: [{ role: "user", content: "What's the weather in Paris?" }],
|
messages: [{ role: "user", content: "What's the weather in Paris?" }],
|
||||||
@@ -174,7 +174,7 @@ for (const block of response.content) {
|
|||||||
const result = await executeTool(block.name, block.input);
|
const result = await executeTool(block.name, block.input);
|
||||||
|
|
||||||
const followup = await client.messages.create({
|
const followup = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
tools: tools,
|
tools: tools,
|
||||||
messages: [
|
messages: [
|
||||||
@@ -198,7 +198,7 @@ for (const block of response.content) {
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
tools: tools,
|
tools: tools,
|
||||||
tool_choice: { type: "tool", name: "get_weather" },
|
tool_choice: { type: "tool", name: "get_weather" },
|
||||||
@@ -217,7 +217,7 @@ Version-suffixed `type` literals; `name` is fixed per interface. Pass plain obje
|
|||||||
```typescript
|
```typescript
|
||||||
// ✓ let inference work — no annotation
|
// ✓ let inference work — no annotation
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
tools: [
|
tools: [
|
||||||
{ type: "text_editor_20250728", name: "str_replace_based_edit_tool" },
|
{ type: "text_editor_20250728", name: "str_replace_based_edit_tool" },
|
||||||
@@ -257,7 +257,7 @@ import Anthropic from "@anthropic-ai/sdk";
|
|||||||
const client = new Anthropic();
|
const client = new Anthropic();
|
||||||
|
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -305,7 +305,7 @@ const uploaded = await client.beta.files.upload({
|
|||||||
// Code execution is GA; Files API is still beta (pass via RequestOptions)
|
// Code execution is GA; Files API is still beta (pass via RequestOptions)
|
||||||
const response = await client.messages.create(
|
const response = await client.messages.create(
|
||||||
{
|
{
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -365,7 +365,7 @@ for (const block of response.content) {
|
|||||||
```typescript
|
```typescript
|
||||||
// First request: set up environment
|
// First request: set up environment
|
||||||
const response1 = await client.messages.create({
|
const response1 = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -382,7 +382,7 @@ const containerId = response1.container!.id;
|
|||||||
|
|
||||||
const response2 = await client.messages.create({
|
const response2 = await client.messages.create({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -402,7 +402,7 @@ const response2 = await client.messages.create({
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -436,7 +436,7 @@ const handlers: MemoryToolHandlers = {
|
|||||||
const memory = betaMemoryTool(handlers);
|
const memory = betaMemoryTool(handlers);
|
||||||
|
|
||||||
const runner = client.beta.messages.toolRunner({
|
const runner = client.beta.messages.toolRunner({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
tools: [memory],
|
tools: [memory],
|
||||||
messages: [{ role: "user", content: "Remember my preferences" }],
|
messages: [{ role: "user", content: "Remember my preferences" }],
|
||||||
@@ -473,7 +473,7 @@ const ContactInfoSchema = z.object({
|
|||||||
const client = new Anthropic();
|
const client = new Anthropic();
|
||||||
|
|
||||||
const response = await client.messages.parse({
|
const response = await client.messages.parse({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -495,7 +495,7 @@ console.log(response.parsed_output!.name); // "Jane Doe"
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ console.log(environment.id); // env_...
|
|||||||
const agent = await client.beta.agents.create(
|
const agent = await client.beta.agents.create(
|
||||||
{
|
{
|
||||||
name: "Coding Assistant",
|
name: "Coding Assistant",
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
tools: [{ type: "agent_toolset_20260401", default_config: { enabled: true } }],
|
tools: [{ type: "agent_toolset_20260401", default_config: { enabled: true } }],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -73,7 +73,7 @@ console.log(session.id, session.status);
|
|||||||
const agent = await client.beta.agents.create(
|
const agent = await client.beta.agents.create(
|
||||||
{
|
{
|
||||||
name: "Code Reviewer",
|
name: "Code Reviewer",
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
system: "You are a senior code reviewer.",
|
system: "You are a senior code reviewer.",
|
||||||
tools: [
|
tools: [
|
||||||
{ type: "agent_toolset_20260401", default_config: { enabled: true } },
|
{ type: "agent_toolset_20260401", default_config: { enabled: true } },
|
||||||
@@ -338,7 +338,7 @@ await client.beta.sessions.archive("sesn_011CZxAbc123Def456");
|
|||||||
// Agent declares MCP server (no auth here — auth goes in a vault)
|
// Agent declares MCP server (no auth here — auth goes in a vault)
|
||||||
const agent = await client.beta.agents.create({
|
const agent = await client.beta.agents.create({
|
||||||
name: "MCP Agent",
|
name: "MCP Agent",
|
||||||
model: "claude-opus-4-7",
|
model: "claude-opus-4-8",
|
||||||
mcp_servers: [
|
mcp_servers: [
|
||||||
{ type: "url", name: "my-tools", url: "https://my-mcp-server.example.com/sse" },
|
{ type: "url", name: "my-tools", url: "https://my-mcp-server.example.com/sse" },
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user