hive-skills 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +235 -0
- package/assets/LICENSE +32 -0
- package/assets/THIRD_PARTY_NOTICES.md +72 -0
- package/assets/manifest.json +1290 -0
- package/assets/skills/authored/code-review/composable/BUNDLE.md +192 -0
- package/assets/skills/authored/code-review/composable/INDEX.md +13 -0
- package/assets/skills/authored/code-review/composable/VERSION +1 -0
- package/assets/skills/authored/code-review/composable/mini/01-review-method.md +34 -0
- package/assets/skills/authored/code-review/composable/mini/02-security-review.md +20 -0
- package/assets/skills/authored/code-review/composable/mini/03-correctness-bugs.md +19 -0
- package/assets/skills/authored/code-review/composable/mini/04-concurrency.md +16 -0
- package/assets/skills/authored/code-review/composable/mini/05-error-handling.md +12 -0
- package/assets/skills/authored/code-review/composable/mini/06-performance.md +11 -0
- package/assets/skills/authored/code-review/composable/mini/07-api-design.md +20 -0
- package/assets/skills/authored/code-review/composable/mini/08-missing-tests.md +25 -0
- package/assets/skills/authored/code-review/composable/mini/09-refactoring-and-communication.md +32 -0
- package/assets/skills/authored/data-analysis/composable/BUNDLE.md +186 -0
- package/assets/skills/authored/data-analysis/composable/INDEX.md +13 -0
- package/assets/skills/authored/data-analysis/composable/VERSION +1 -0
- package/assets/skills/authored/data-analysis/composable/mini/01-data-quality-profiling.md +26 -0
- package/assets/skills/authored/data-analysis/composable/mini/02-aggregation-pitfalls.md +21 -0
- package/assets/skills/authored/data-analysis/composable/mini/03-time-series.md +19 -0
- package/assets/skills/authored/data-analysis/composable/mini/04-segmentation.md +23 -0
- package/assets/skills/authored/data-analysis/composable/mini/05-discount-pricing.md +17 -0
- package/assets/skills/authored/data-analysis/composable/mini/06-insight-generation.md +25 -0
- package/assets/skills/authored/data-analysis/composable/mini/07-executive-writing.md +26 -0
- package/assets/skills/authored/data-analysis/composable/mini/08-recommendations.md +20 -0
- package/assets/skills/authored/data-analysis/composable/mini/09-reproducibility-assumptions.md +20 -0
- package/assets/skills/authored/financial-analysis/composable/BUNDLE.md +1293 -0
- package/assets/skills/authored/financial-analysis/composable/INDEX.md +17 -0
- package/assets/skills/authored/financial-analysis/composable/VERSION +1 -0
- package/assets/skills/authored/financial-analysis/composable/mini/00-core.md +69 -0
- package/assets/skills/authored/financial-analysis/composable/mini/01-profitability-efficiency-ratios.md +173 -0
- package/assets/skills/authored/financial-analysis/composable/mini/02-liquidity-leverage-ratios.md +120 -0
- package/assets/skills/authored/financial-analysis/composable/mini/03-valuation-ratios-interpretation.md +107 -0
- package/assets/skills/authored/financial-analysis/composable/mini/04-dcf-projection-wacc.md +122 -0
- package/assets/skills/authored/financial-analysis/composable/mini/05-dcf-terminal-value-sensitivity.md +75 -0
- package/assets/skills/authored/financial-analysis/composable/mini/06-comparables-precedents.md +78 -0
- package/assets/skills/authored/financial-analysis/composable/mini/07-budget-variance-analysis.md +47 -0
- package/assets/skills/authored/financial-analysis/composable/mini/08-driver-based-forecasting-scenarios.md +111 -0
- package/assets/skills/authored/financial-analysis/composable/mini/09-rolling-forecasts-accuracy.md +114 -0
- package/assets/skills/authored/financial-analysis/composable/mini/10-reporting-exec-summary.md +58 -0
- package/assets/skills/authored/financial-analysis/composable/mini/11-industry-adaptations.md +130 -0
- package/assets/skills/authored/financial-analysis/composable/mini/12-toolkit-scripts-io.md +102 -0
- package/assets/skills/authored/python-api/composable/BUNDLE.md +389 -0
- package/assets/skills/authored/python-api/composable/INDEX.md +13 -0
- package/assets/skills/authored/python-api/composable/VERSION +1 -0
- package/assets/skills/authored/python-api/composable/mini/01-project-structure.md +44 -0
- package/assets/skills/authored/python-api/composable/mini/02-routing-and-app.md +38 -0
- package/assets/skills/authored/python-api/composable/mini/03-pydantic-models.md +45 -0
- package/assets/skills/authored/python-api/composable/mini/04-validation-and-errors.md +59 -0
- package/assets/skills/authored/python-api/composable/mini/05-dependencies-and-auth.md +60 -0
- package/assets/skills/authored/python-api/composable/mini/06-pagination-filtering.md +44 -0
- package/assets/skills/authored/python-api/composable/mini/07-async-performance.md +30 -0
- package/assets/skills/authored/python-api/composable/mini/08-testing.md +45 -0
- package/assets/skills/authored/python-api/composable/mini/09-middleware-observability.md +29 -0
- package/assets/skills/authored/tech-writing/composable/BUNDLE.md +220 -0
- package/assets/skills/authored/tech-writing/composable/INDEX.md +12 -0
- package/assets/skills/authored/tech-writing/composable/VERSION +1 -0
- package/assets/skills/authored/tech-writing/composable/mini/01-audience-analysis.md +26 -0
- package/assets/skills/authored/tech-writing/composable/mini/02-document-types.md +27 -0
- package/assets/skills/authored/tech-writing/composable/mini/03-readme-quickstart-changelog.md +22 -0
- package/assets/skills/authored/tech-writing/composable/mini/04-information-architecture.md +21 -0
- package/assets/skills/authored/tech-writing/composable/mini/05-style-clarity.md +29 -0
- package/assets/skills/authored/tech-writing/composable/mini/06-breaking-changes-migrations.md +33 -0
- package/assets/skills/authored/tech-writing/composable/mini/07-troubleshooting-security.md +30 -0
- package/assets/skills/authored/tech-writing/composable/mini/08-faq-voice-tone.md +32 -0
- package/assets/skills/converted/claude-api/composable/BUNDLE.md +14996 -0
- package/assets/skills/converted/claude-api/composable/INDEX.md +98 -0
- package/assets/skills/converted/claude-api/composable/VERSION +1 -0
- package/assets/skills/converted/claude-api/composable/mini/00-core.md +235 -0
- package/assets/skills/converted/claude-api/composable/mini/01-model-api-quick-reference.md +258 -0
- package/assets/skills/converted/claude-api/composable/mini/02-common-pitfalls.md +42 -0
- package/assets/skills/converted/claude-api/composable/mini/10-models.md +135 -0
- package/assets/skills/converted/claude-api/composable/mini/11-platform-availability.md +96 -0
- package/assets/skills/converted/claude-api/composable/mini/12-claude-platform-on-aws.md +59 -0
- package/assets/skills/converted/claude-api/composable/mini/13-live-sources.md +143 -0
- package/assets/skills/converted/claude-api/composable/mini/14-error-codes.md +256 -0
- package/assets/skills/converted/claude-api/composable/mini/15-prompt-caching.md +223 -0
- package/assets/skills/converted/claude-api/composable/mini/16-token-counting.md +56 -0
- package/assets/skills/converted/claude-api/composable/mini/17-tool-use-concepts.md +444 -0
- package/assets/skills/converted/claude-api/composable/mini/18-agent-design.md +101 -0
- package/assets/skills/converted/claude-api/composable/mini/19-anthropic-cli.md +246 -0
- package/assets/skills/converted/claude-api/composable/mini/20-model-migration.md +1301 -0
- package/assets/skills/converted/claude-api/composable/mini/30-managed-agents-overview.md +71 -0
- package/assets/skills/converted/claude-api/composable/mini/31-managed-agents-core.md +278 -0
- package/assets/skills/converted/claude-api/composable/mini/32-managed-agents-environments.md +219 -0
- package/assets/skills/converted/claude-api/composable/mini/33-managed-agents-tools.md +366 -0
- package/assets/skills/converted/claude-api/composable/mini/34-managed-agents-events.md +252 -0
- package/assets/skills/converted/claude-api/composable/mini/35-managed-agents-outcomes.md +106 -0
- package/assets/skills/converted/claude-api/composable/mini/36-managed-agents-multiagent.md +101 -0
- package/assets/skills/converted/claude-api/composable/mini/37-managed-agents-webhooks.md +123 -0
- package/assets/skills/converted/claude-api/composable/mini/38-managed-agents-memory.md +197 -0
- package/assets/skills/converted/claude-api/composable/mini/39-managed-agents-scheduled-deployments.md +146 -0
- package/assets/skills/converted/claude-api/composable/mini/40-managed-agents-client-patterns.md +211 -0
- package/assets/skills/converted/claude-api/composable/mini/41-managed-agents-onboarding.md +82 -0
- package/assets/skills/converted/claude-api/composable/mini/42-managed-agents-api-reference.md +441 -0
- package/assets/skills/converted/claude-api/composable/mini/43-managed-agents-self-hosted-sandboxes.md +174 -0
- package/assets/skills/converted/claude-api/composable/mini/50-python-readme.md +564 -0
- package/assets/skills/converted/claude-api/composable/mini/51-python-tool-use.md +590 -0
- package/assets/skills/converted/claude-api/composable/mini/52-python-streaming-batches-files.md +549 -0
- package/assets/skills/converted/claude-api/composable/mini/53-python-managed-agents.md +335 -0
- package/assets/skills/converted/claude-api/composable/mini/55-typescript-readme.md +404 -0
- package/assets/skills/converted/claude-api/composable/mini/56-typescript-tool-use.md +548 -0
- package/assets/skills/converted/claude-api/composable/mini/57-typescript-streaming-batches-files.md +384 -0
- package/assets/skills/converted/claude-api/composable/mini/58-typescript-managed-agents.md +358 -0
- package/assets/skills/converted/claude-api/composable/mini/60-csharp-readme.md +361 -0
- package/assets/skills/converted/claude-api/composable/mini/61-csharp-tool-use.md +163 -0
- package/assets/skills/converted/claude-api/composable/mini/62-csharp-streaming-batches-files.md +64 -0
- package/assets/skills/converted/claude-api/composable/mini/65-go-readme.md +185 -0
- package/assets/skills/converted/claude-api/composable/mini/66-go-tool-use.md +219 -0
- package/assets/skills/converted/claude-api/composable/mini/67-go-streaming-files.md +63 -0
- package/assets/skills/converted/claude-api/composable/mini/68-go-managed-agents.md +564 -0
- package/assets/skills/converted/claude-api/composable/mini/70-java-readme.md +237 -0
- package/assets/skills/converted/claude-api/composable/mini/71-java-tool-use.md +227 -0
- package/assets/skills/converted/claude-api/composable/mini/72-java-streaming-files.md +49 -0
- package/assets/skills/converted/claude-api/composable/mini/73-java-managed-agents.md +443 -0
- package/assets/skills/converted/claude-api/composable/mini/75-php-readme.md +173 -0
- package/assets/skills/converted/claude-api/composable/mini/76-php-tool-use.md +252 -0
- package/assets/skills/converted/claude-api/composable/mini/77-php-streaming-batches-files.md +53 -0
- package/assets/skills/converted/claude-api/composable/mini/78-php-managed-agents.md +443 -0
- package/assets/skills/converted/claude-api/composable/mini/80-ruby-readme.md +133 -0
- package/assets/skills/converted/claude-api/composable/mini/81-ruby-tool-use-streaming.md +56 -0
- package/assets/skills/converted/claude-api/composable/mini/82-ruby-managed-agents.md +394 -0
- package/assets/skills/converted/claude-api/composable/mini/85-curl-examples.md +255 -0
- package/assets/skills/converted/claude-api/composable/mini/86-curl-managed-agents.md +340 -0
- package/assets/skills/converted/claude-api/composable/presets/csharp.md +1151 -0
- package/assets/skills/converted/claude-api/composable/presets/curl.md +1154 -0
- package/assets/skills/converted/claude-api/composable/presets/go.md +1598 -0
- package/assets/skills/converted/claude-api/composable/presets/java.md +1523 -0
- package/assets/skills/converted/claude-api/composable/presets/php.md +1488 -0
- package/assets/skills/converted/claude-api/composable/presets/python.md +2605 -0
- package/assets/skills/converted/claude-api/composable/presets/ruby.md +1146 -0
- package/assets/skills/converted/claude-api/composable/presets/shared.md +6478 -0
- package/assets/skills/converted/claude-api/composable/presets/typescript.md +2261 -0
- package/assets/skills/converted/docx/composable/BUNDLE.md +617 -0
- package/assets/skills/converted/docx/composable/INDEX.md +12 -0
- package/assets/skills/converted/docx/composable/VERSION +1 -0
- package/assets/skills/converted/docx/composable/mini/00-core.md +26 -0
- package/assets/skills/converted/docx/composable/mini/01-reading-converting.md +36 -0
- package/assets/skills/converted/docx/composable/mini/02-creating-setup-layout.md +85 -0
- package/assets/skills/converted/docx/composable/mini/03-creating-elements.md +257 -0
- package/assets/skills/converted/docx/composable/mini/04-editing-existing.md +57 -0
- package/assets/skills/converted/docx/composable/mini/05-xml-reference.md +128 -0
- package/assets/skills/converted/internal-comms/composable/BUNDLE.md +220 -0
- package/assets/skills/converted/internal-comms/composable/INDEX.md +11 -0
- package/assets/skills/converted/internal-comms/composable/VERSION +1 -0
- package/assets/skills/converted/internal-comms/composable/mini/00-core.md +30 -0
- package/assets/skills/converted/internal-comms/composable/mini/01-3p-updates.md +49 -0
- package/assets/skills/converted/internal-comms/composable/mini/02-company-newsletter.md +67 -0
- package/assets/skills/converted/internal-comms/composable/mini/03-faq-answers.md +32 -0
- package/assets/skills/converted/internal-comms/composable/mini/04-general-comms.md +18 -0
- package/assets/skills/converted/mcp-builder/composable/BUNDLE.md +2460 -0
- package/assets/skills/converted/mcp-builder/composable/INDEX.md +23 -0
- package/assets/skills/converted/mcp-builder/composable/VERSION +1 -0
- package/assets/skills/converted/mcp-builder/composable/mini/00-core.md +43 -0
- package/assets/skills/converted/mcp-builder/composable/mini/01-workflow-research-planning.md +54 -0
- package/assets/skills/converted/mcp-builder/composable/mini/02-implementation-process.md +78 -0
- package/assets/skills/converted/mcp-builder/composable/mini/03-naming-conventions.md +33 -0
- package/assets/skills/converted/mcp-builder/composable/mini/04-response-formats.md +21 -0
- package/assets/skills/converted/mcp-builder/composable/mini/05-pagination.md +24 -0
- package/assets/skills/converted/mcp-builder/composable/mini/06-transport.md +47 -0
- package/assets/skills/converted/mcp-builder/composable/mini/07-annotations.md +20 -0
- package/assets/skills/converted/mcp-builder/composable/mini/08-security.md +35 -0
- package/assets/skills/converted/mcp-builder/composable/mini/09-error-handling.md +32 -0
- package/assets/skills/converted/mcp-builder/composable/mini/10-testing-and-documentation.md +21 -0
- package/assets/skills/converted/mcp-builder/composable/mini/11-python-implementation.md +432 -0
- package/assets/skills/converted/mcp-builder/composable/mini/12-python-advanced-and-checklist.md +233 -0
- package/assets/skills/converted/mcp-builder/composable/mini/13-node-implementation.md +717 -0
- package/assets/skills/converted/mcp-builder/composable/mini/14-node-advanced-and-checklist.md +200 -0
- package/assets/skills/converted/mcp-builder/composable/mini/15-evaluation-design.md +200 -0
- package/assets/skills/converted/mcp-builder/composable/mini/16-evaluation-running.md +198 -0
- package/assets/skills/converted/mcp-builder/composable/presets/node-server.md +1381 -0
- package/assets/skills/converted/mcp-builder/composable/presets/python-server.md +1129 -0
- package/assets/skills/converted/pdf/composable/BUNDLE.md +1284 -0
- package/assets/skills/converted/pdf/composable/INDEX.md +14 -0
- package/assets/skills/converted/pdf/composable/VERSION +1 -0
- package/assets/skills/converted/pdf/composable/mini/00-core.md +46 -0
- package/assets/skills/converted/pdf/composable/mini/01-creation.md +176 -0
- package/assets/skills/converted/pdf/composable/mini/02-extraction.md +178 -0
- package/assets/skills/converted/pdf/composable/mini/03-merge-split-manipulate.md +240 -0
- package/assets/skills/converted/pdf/composable/mini/04-images-ocr.md +168 -0
- package/assets/skills/converted/pdf/composable/mini/05-encryption.md +51 -0
- package/assets/skills/converted/pdf/composable/mini/06-forms.md +300 -0
- package/assets/skills/converted/pdf/composable/mini/07-libraries-reference.md +89 -0
- package/assets/skills/converted/pptx/composable/BUNDLE.md +911 -0
- package/assets/skills/converted/pptx/composable/INDEX.md +12 -0
- package/assets/skills/converted/pptx/composable/VERSION +1 -0
- package/assets/skills/converted/pptx/composable/mini/00-core.md +37 -0
- package/assets/skills/converted/pptx/composable/mini/01-reading.md +37 -0
- package/assets/skills/converted/pptx/composable/mini/02-creating-from-scratch.md +422 -0
- package/assets/skills/converted/pptx/composable/mini/03-editing-templates.md +207 -0
- package/assets/skills/converted/pptx/composable/mini/04-design.md +89 -0
- package/assets/skills/converted/pptx/composable/mini/05-qa-and-rendering.md +91 -0
- package/assets/skills/converted/pptx/composable/presets/creating.md +659 -0
- package/assets/skills/converted/pptx/composable/presets/editing.md +485 -0
- package/assets/skills/converted/skill-creator/composable/BUNDLE.md +1681 -0
- package/assets/skills/converted/skill-creator/composable/INDEX.md +21 -0
- package/assets/skills/converted/skill-creator/composable/VERSION +1 -0
- package/assets/skills/converted/skill-creator/composable/mini/00-core.md +59 -0
- package/assets/skills/converted/skill-creator/composable/mini/01-creating-a-skill.md +27 -0
- package/assets/skills/converted/skill-creator/composable/mini/02-skill-writing-guide.md +71 -0
- package/assets/skills/converted/skill-creator/composable/mini/03-test-cases.md +21 -0
- package/assets/skills/converted/skill-creator/composable/mini/04-running-and-evaluating.md +128 -0
- package/assets/skills/converted/skill-creator/composable/mini/05-improving-the-skill.md +30 -0
- package/assets/skills/converted/skill-creator/composable/mini/06-blind-comparison.md +5 -0
- package/assets/skills/converted/skill-creator/composable/mini/07-description-optimization.md +74 -0
- package/assets/skills/converted/skill-creator/composable/mini/08-packaging.md +11 -0
- package/assets/skills/converted/skill-creator/composable/mini/09-environment-specific.md +38 -0
- package/assets/skills/converted/skill-creator/composable/mini/10-scripts-and-references.md +34 -0
- package/assets/skills/converted/skill-creator/composable/mini/11-json-schemas.md +414 -0
- package/assets/skills/converted/skill-creator/composable/mini/12-agent-grader.md +225 -0
- package/assets/skills/converted/skill-creator/composable/mini/13-agent-comparator.md +204 -0
- package/assets/skills/converted/skill-creator/composable/mini/14-agent-analyzer.md +276 -0
- package/assets/skills/converted/skill-creator/composable/presets/authoring.md +198 -0
- package/assets/skills/converted/skill-creator/composable/presets/evaluating.md +1334 -0
- package/assets/skills/converted/skill-creator/composable/presets/optimizing.md +160 -0
- package/assets/skills/converted/skill-creator/composable/presets.json +5 -0
- package/assets/skills/meta/ccs-skill-creator/composable/BUNDLE.md +465 -0
- package/assets/skills/meta/ccs-skill-creator/composable/INDEX.md +8 -0
- package/assets/skills/meta/ccs-skill-creator/composable/VERSION +1 -0
- package/assets/skills/meta/ccs-skill-creator/composable/mini/00-core.md +46 -0
- package/assets/skills/meta/ccs-skill-creator/composable/mini/01-create-new-skill.md +167 -0
- package/assets/skills/meta/ccs-skill-creator/composable/mini/02-convert-existing-skill.md +120 -0
- package/assets/skills/meta/ccs-skill-creator/composable/mini/03-review-and-maintain.md +112 -0
- package/assets/skills/sources/anthropic/PROVENANCE.md +3 -0
- package/assets/skills/sources/anthropic/claude-api/LICENSE.txt +202 -0
- package/assets/skills/sources/anthropic/docx/LICENSE.txt +30 -0
- package/assets/skills/sources/anthropic/internal-comms/LICENSE.txt +202 -0
- package/assets/skills/sources/anthropic/mcp-builder/LICENSE.txt +202 -0
- package/assets/skills/sources/anthropic/pdf/LICENSE.txt +30 -0
- package/assets/skills/sources/anthropic/pptx/LICENSE.txt +30 -0
- package/assets/skills/sources/anthropic/skill-creator/LICENSE.txt +202 -0
- package/assets/skills/sources/financial-analyst/PROVENANCE.md +1 -0
- package/assets/tools/hive.py +728 -0
- package/dist/cli.js +7494 -0
- package/package.json +40 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Claude API — Java
|
|
2
|
+
|
|
3
|
+
> **Note:** The Java SDK supports the Claude API and beta tool use with annotated classes. Agent SDK is not yet available for Java.
|
|
4
|
+
|
|
5
|
+
## Package Reference
|
|
6
|
+
|
|
7
|
+
Types are organized by package. If a class you need isn't shown in an example below, locate it via this table first — don't block on fetching SDK source over the network.
|
|
8
|
+
|
|
9
|
+
| `import` prefix | Contains |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `com.anthropic.client` / `com.anthropic.client.okhttp` | `AnthropicClient`, `AnthropicOkHttpClient` |
|
|
12
|
+
| `com.anthropic.models.messages` | non-beta request/response types — `MessageCreateParams`, `Model`, `Message`, `TextBlockParam`, `ContentBlockParam`, `ToolUseBlockParam`, `ToolResultBlockParam`, `CacheControlEphemeral`, `Tool*` (e.g. `ToolBash20250124`, `ToolTextEditor20250728`), `StopReason`, `StructuredMessage*` |
|
|
13
|
+
| `com.anthropic.models.messages.batches` | Batch API — `BatchResultsParams`, `MessageBatchIndividualResponse` |
|
|
14
|
+
| `com.anthropic.models.beta` | `AnthropicBeta` (beta-flag constants) |
|
|
15
|
+
| `com.anthropic.models.beta.messages` | beta-endpoint types — `MessageCreateParams`, `BetaMessage`, `BetaStopReason`, `BetaContextManagementConfig`, `BetaMcpToolset`, `BetaRequestMcpServerUrlDefinition`, `BetaTool*` |
|
|
16
|
+
| `com.anthropic.core` | `JsonValue`, `JsonField`, `JsonSchemaLocalValidation`, `com.anthropic.core.http.StreamResponse` |
|
|
17
|
+
| `com.anthropic.errors` | typed exceptions — `AnthropicServiceException`, `RateLimitException`, `NotFoundException`, etc. (see `shared/error-codes.md`) |
|
|
18
|
+
|
|
19
|
+
`client.messages()` uses `com.anthropic.models.messages.*`; `client.beta().messages()` uses `com.anthropic.models.beta.messages.*`. Both packages define a `MessageCreateParams` — import the one matching the client path you call.
|
|
20
|
+
|
|
21
|
+
### Key types per feature
|
|
22
|
+
|
|
23
|
+
Write from this table instead of `javap`/jar inspection. Endpoint column tells you whether to use `client.messages()` or `client.beta().messages()`.
|
|
24
|
+
|
|
25
|
+
| Feature | Endpoint | Key Java types / builder calls |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| User profiles | beta | `client.beta().userProfiles().create(...)` / `.retrieve(id)` / `.list()`. Pass the returned profile id on the beta `MessageCreateParams`. Requires a beta header — check the SDK's beta-headers reference for the current flag. |
|
|
28
|
+
| Agent Skills | beta | `BetaContainerParams`, `BetaSkillParams`, `BetaCodeExecutionTool20250825`. `.addBeta("code-execution-2025-08-25").addBeta("skills-2025-10-02")`. Download the output via `client.beta().files().download(fileId)`. |
|
|
29
|
+
| Cache diagnostics | beta | `BetaDiagnosticsParam`, `BetaCacheControlEphemeral` |
|
|
30
|
+
| Context editing | beta | `.contextManagement(BetaContextManagementConfig.builder()…)`. The edit strategy is a `BetaClearToolUses20250919Edit` (or `BetaClearThinking20251015Edit`); its trigger is a `BetaInputTokensTrigger` built separately and passed to the edit's builder — there is no direct `.inputTokensTrigger(N)` shortcut on the edit builder. `javap` the edit and trigger classes for the exact setter names. |
|
|
31
|
+
| Memory tool | non-beta | `.addTool(MemoryTool20250818.builder().build())` from `com.anthropic.models.messages` |
|
|
32
|
+
| Programmatic tool calling | non-beta | `CodeExecutionTool20260120`, `Tool`, `ContentBlockParam` |
|
|
33
|
+
| Strict tool use | non-beta | `Tool`, `Tool.InputSchema` |
|
|
34
|
+
| Task budgets | beta | `.outputConfig(BetaOutputConfig.builder().taskBudget(BetaTokenTaskBudget.builder()...))` |
|
|
35
|
+
| Tool search | non-beta | `.addTool(ToolSearchToolRegex20251119.builder()...)` from `com.anthropic.models.messages` |
|
|
36
|
+
| Web search | non-beta | `WebSearchTool20260209` from `com.anthropic.models.messages` — the latest variant with dynamic filtering (Opus 4.8/4.7/4.6 + Sonnet 4.6). For older models or Vertex, use `WebSearchTool20250305` |
|
|
37
|
+
|
|
38
|
+
### Discovering type and member names
|
|
39
|
+
|
|
40
|
+
If a class or builder method you need isn't in the tables above, `jar tf <anthropic-java-core jar> | grep -i <term>` or `javap -classpath <jar> com.anthropic.models.…` is fast enough to locate names. **Do not compile and run a separate reflection program** to enumerate members — the first build is slow enough to be backgrounded in many environments, trapping you in a polling loop. Write the script with the names you found and let the compiler error (`cannot find symbol`) point at any wrong member.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
Maven:
|
|
45
|
+
|
|
46
|
+
```xml
|
|
47
|
+
<dependency>
|
|
48
|
+
<groupId>com.anthropic</groupId>
|
|
49
|
+
<artifactId>anthropic-java</artifactId>
|
|
50
|
+
<version>2.34.0</version>
|
|
51
|
+
</dependency>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Gradle:
|
|
55
|
+
|
|
56
|
+
```groovy
|
|
57
|
+
implementation("com.anthropic:anthropic-java:2.34.0")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Client Initialization
|
|
61
|
+
|
|
62
|
+
```java
|
|
63
|
+
import com.anthropic.client.AnthropicClient;
|
|
64
|
+
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
|
|
65
|
+
|
|
66
|
+
// Default (reads ANTHROPIC_API_KEY from environment)
|
|
67
|
+
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
|
|
68
|
+
|
|
69
|
+
// Explicit API key
|
|
70
|
+
AnthropicClient client = AnthropicOkHttpClient.builder()
|
|
71
|
+
.apiKey("your-api-key")
|
|
72
|
+
.build();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Basic Message Request
|
|
78
|
+
|
|
79
|
+
```java
|
|
80
|
+
import com.anthropic.models.messages.MessageCreateParams;
|
|
81
|
+
import com.anthropic.models.messages.Message;
|
|
82
|
+
import com.anthropic.models.messages.Model;
|
|
83
|
+
|
|
84
|
+
MessageCreateParams params = MessageCreateParams.builder()
|
|
85
|
+
.model(Model.CLAUDE_OPUS_4_8)
|
|
86
|
+
.maxTokens(16000L)
|
|
87
|
+
.addUserMessage("What is the capital of France?")
|
|
88
|
+
.build();
|
|
89
|
+
|
|
90
|
+
Message response = client.messages().create(params);
|
|
91
|
+
response.content().stream()
|
|
92
|
+
.flatMap(block -> block.text().stream())
|
|
93
|
+
.forEach(textBlock -> System.out.println(textBlock.text()));
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Thinking
|
|
99
|
+
|
|
100
|
+
**Adaptive thinking is the recommended mode for Claude 4.6+ models.** Claude decides dynamically when and how much to think. The builder has a direct `.thinking(ThinkingConfigAdaptive)` overload — no manual union wrapping.
|
|
101
|
+
|
|
102
|
+
> **Fable 5, Opus 4.8, Opus 4.7, Opus 4.6, and Sonnet 4.6:** Use adaptive thinking (below). `ThinkingConfigEnabled.builder().budgetTokens(N)` is removed on Fable 5, Opus 4.8, and 4.7 (400 if sent); deprecated on Opus 4.6 and Sonnet 4.6.
|
|
103
|
+
> **Older models:** Use `.thinking(ThinkingConfigEnabled.builder().budgetTokens(N).build())` (budget must be < `maxTokens`, min 1024).
|
|
104
|
+
|
|
105
|
+
```java
|
|
106
|
+
import com.anthropic.models.messages.ContentBlock;
|
|
107
|
+
import com.anthropic.models.messages.MessageCreateParams;
|
|
108
|
+
import com.anthropic.models.messages.Model;
|
|
109
|
+
import com.anthropic.models.messages.ThinkingConfigAdaptive;
|
|
110
|
+
|
|
111
|
+
MessageCreateParams params = MessageCreateParams.builder()
|
|
112
|
+
.model(Model.CLAUDE_SONNET_4_6)
|
|
113
|
+
.maxTokens(16000L)
|
|
114
|
+
.thinking(ThinkingConfigAdaptive.builder().build())
|
|
115
|
+
.addUserMessage("Solve this step by step: 27 * 453")
|
|
116
|
+
.build();
|
|
117
|
+
|
|
118
|
+
for (ContentBlock block : client.messages().create(params).content()) {
|
|
119
|
+
block.thinking().ifPresent(t -> System.out.println("[thinking] " + t.thinking()));
|
|
120
|
+
block.text().ifPresent(t -> System.out.println(t.text()));
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`ContentBlock` narrowing: `.thinking()` / `.text()` return `Optional<T>` — use `.ifPresent(...)` or `.stream().flatMap(...)`. Alternative: `isThinking()` / `asThinking()` boolean+unwrap pairs (throws on wrong variant).
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Effort Parameter
|
|
129
|
+
|
|
130
|
+
Effort is nested inside `OutputConfig` — there is NO `.effort()` directly on `MessageCreateParams.Builder`.
|
|
131
|
+
|
|
132
|
+
```java
|
|
133
|
+
import com.anthropic.models.messages.OutputConfig;
|
|
134
|
+
|
|
135
|
+
.outputConfig(OutputConfig.builder()
|
|
136
|
+
.effort(OutputConfig.Effort.HIGH) // or LOW, MEDIUM, MAX
|
|
137
|
+
.build())
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Combine with `Thinking = ThinkingConfigAdaptive` for cost-quality control.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Prompt Caching
|
|
145
|
+
|
|
146
|
+
System message as a list of `TextBlockParam` with `CacheControlEphemeral`. Use `.systemOfTextBlockParams(...)` — the plain `.system(String)` overload can't carry cache control. For placement patterns and the silent-invalidator audit checklist, see `shared/prompt-caching.md`.
|
|
147
|
+
|
|
148
|
+
```java
|
|
149
|
+
import com.anthropic.models.messages.TextBlockParam;
|
|
150
|
+
import com.anthropic.models.messages.CacheControlEphemeral;
|
|
151
|
+
|
|
152
|
+
.systemOfTextBlockParams(List.of(
|
|
153
|
+
TextBlockParam.builder()
|
|
154
|
+
.text(longSystemPrompt)
|
|
155
|
+
.cacheControl(CacheControlEphemeral.builder()
|
|
156
|
+
.ttl(CacheControlEphemeral.Ttl.TTL_1H) // optional; also TTL_5M
|
|
157
|
+
.build())
|
|
158
|
+
.build()))
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
There's also a top-level `.cacheControl(CacheControlEphemeral)` on `MessageCreateParams.Builder` and on `Tool.builder()`.
|
|
162
|
+
|
|
163
|
+
Verify hits via `response.usage().cacheCreationInputTokens()` / `response.usage().cacheReadInputTokens()`.
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Token Counting
|
|
168
|
+
|
|
169
|
+
```java
|
|
170
|
+
import com.anthropic.models.messages.MessageCountTokensParams;
|
|
171
|
+
|
|
172
|
+
long tokens = client.messages().countTokens(
|
|
173
|
+
MessageCountTokensParams.builder()
|
|
174
|
+
.model(Model.CLAUDE_SONNET_4_6)
|
|
175
|
+
.addUserMessage("Hello")
|
|
176
|
+
.build()
|
|
177
|
+
).inputTokens();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## PDF / Document Input
|
|
183
|
+
|
|
184
|
+
`DocumentBlockParam` builder has source shortcuts. Wrap in `ContentBlockParam.ofDocument()` and pass via `.addUserMessageOfBlockParams()`.
|
|
185
|
+
|
|
186
|
+
```java
|
|
187
|
+
import com.anthropic.models.messages.DocumentBlockParam;
|
|
188
|
+
import com.anthropic.models.messages.ContentBlockParam;
|
|
189
|
+
import com.anthropic.models.messages.TextBlockParam;
|
|
190
|
+
|
|
191
|
+
DocumentBlockParam doc = DocumentBlockParam.builder()
|
|
192
|
+
.source(Base64PdfSource.builder().data(base64String).build())
|
|
193
|
+
// or .source(UrlPdfSource.builder().url("https://...").build())
|
|
194
|
+
.title("My Document") // optional
|
|
195
|
+
.build();
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
For **Files API** document references, use the beta path and beta types — see `files-api.md`: `BetaRequestDocumentBlock.builder().source(BetaFileDocumentSource.builder().fileId(id).build())`.
|
|
199
|
+
|
|
200
|
+
```java
|
|
201
|
+
.addUserMessageOfBlockParams(List.of(
|
|
202
|
+
ContentBlockParam.ofDocument(doc),
|
|
203
|
+
ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this").build())))
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Stop Details
|
|
209
|
+
|
|
210
|
+
When `stopReason()` is `"refusal"`, the response includes structured `stopDetails()`:
|
|
211
|
+
|
|
212
|
+
```java
|
|
213
|
+
response.stopDetails().ifPresent(details -> {
|
|
214
|
+
System.out.println("Category: " + details.category());
|
|
215
|
+
System.out.println("Explanation: " + details.explanation());
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**Refusal fallbacks (Claude Fable 5) — opt in by default.** Fallbacks are opt-in: without them a refused request simply stops. New `claude-fable-5` code should include the server-side `fallbacks` parameter (beta header `server-side-fallback-2026-06-01`, fallback model `claude-opus-4-8`, on the beta messages call) by default. The exact Java builder methods (and the client-side middleware for providers without server-side support) are not documented here — WebFetch the Java SDK repo's `examples/` from `shared/live-sources.md`; full semantics in `shared/model-migration.md` → Migrating to Claude Fable 5 → `refusal` stop reason.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Error Type
|
|
224
|
+
|
|
225
|
+
`AnthropicServiceException` exposes `.errorType()` returning `Optional<ErrorType>` for programmatic error classification:
|
|
226
|
+
|
|
227
|
+
```java
|
|
228
|
+
try {
|
|
229
|
+
client.messages().create(params);
|
|
230
|
+
} catch (AnthropicServiceException e) {
|
|
231
|
+
e.errorType().ifPresent(type ->
|
|
232
|
+
System.out.println("Error type: " + type) // RATE_LIMIT_ERROR, OVERLOADED_ERROR, etc.
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# Tool Use — Java
|
|
2
|
+
|
|
3
|
+
For conceptual overview (tool definitions, tool choice, tips), see [shared/tool-use-concepts.md](../../shared/tool-use-concepts.md).
|
|
4
|
+
|
|
5
|
+
## Tool Use (Beta)
|
|
6
|
+
|
|
7
|
+
The Java SDK supports beta tool use with annotated classes. Tool classes implement `Supplier<String>` for automatic execution via `BetaToolRunner`.
|
|
8
|
+
|
|
9
|
+
### Tool Runner (automatic loop)
|
|
10
|
+
|
|
11
|
+
```java
|
|
12
|
+
import com.anthropic.models.beta.messages.MessageCreateParams;
|
|
13
|
+
import com.anthropic.models.beta.messages.BetaMessage;
|
|
14
|
+
import com.anthropic.helpers.BetaToolRunner;
|
|
15
|
+
import com.fasterxml.jackson.annotation.JsonClassDescription;
|
|
16
|
+
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
|
|
17
|
+
import java.util.function.Supplier;
|
|
18
|
+
|
|
19
|
+
@JsonClassDescription("Get the weather in a given location")
|
|
20
|
+
static class GetWeather implements Supplier<String> {
|
|
21
|
+
@JsonPropertyDescription("The city and state, e.g. San Francisco, CA")
|
|
22
|
+
public String location;
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public String get() {
|
|
26
|
+
return "The weather in " + location + " is sunny and 72°F";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
BetaToolRunner toolRunner = client.beta().messages().toolRunner(
|
|
31
|
+
MessageCreateParams.builder()
|
|
32
|
+
.model("claude-opus-4-8")
|
|
33
|
+
.maxTokens(16000L)
|
|
34
|
+
.putAdditionalHeader("anthropic-beta", "structured-outputs-2025-11-13")
|
|
35
|
+
.addTool(GetWeather.class)
|
|
36
|
+
.addUserMessage("What's the weather in San Francisco?")
|
|
37
|
+
.build());
|
|
38
|
+
|
|
39
|
+
for (BetaMessage message : toolRunner) {
|
|
40
|
+
System.out.println(message);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Memory Tool
|
|
45
|
+
|
|
46
|
+
The Java SDK provides `BetaMemoryToolHandler` for implementing the memory tool backend. You supply a handler that manages file storage, and the `BetaToolRunner` handles memory tool calls automatically.
|
|
47
|
+
|
|
48
|
+
```java
|
|
49
|
+
import com.anthropic.helpers.BetaMemoryToolHandler;
|
|
50
|
+
import com.anthropic.helpers.BetaToolRunner;
|
|
51
|
+
import com.anthropic.models.beta.messages.BetaMemoryTool20250818;
|
|
52
|
+
import com.anthropic.models.beta.messages.BetaMessage;
|
|
53
|
+
import com.anthropic.models.beta.messages.MessageCreateParams;
|
|
54
|
+
import com.anthropic.models.beta.messages.ToolRunnerCreateParams;
|
|
55
|
+
|
|
56
|
+
// Implement BetaMemoryToolHandler with your storage backend (e.g., filesystem)
|
|
57
|
+
BetaMemoryToolHandler memoryHandler = new FileSystemMemoryToolHandler(sandboxRoot);
|
|
58
|
+
|
|
59
|
+
MessageCreateParams createParams = MessageCreateParams.builder()
|
|
60
|
+
.model("claude-opus-4-8")
|
|
61
|
+
.maxTokens(4096L)
|
|
62
|
+
.addTool(BetaMemoryTool20250818.builder().build())
|
|
63
|
+
.addUserMessage("Remember that my favorite color is blue")
|
|
64
|
+
.build();
|
|
65
|
+
|
|
66
|
+
BetaToolRunner toolRunner = client.beta().messages().toolRunner(
|
|
67
|
+
ToolRunnerCreateParams.builder()
|
|
68
|
+
.betaMemoryToolHandler(memoryHandler)
|
|
69
|
+
.initialMessageParams(createParams)
|
|
70
|
+
.build());
|
|
71
|
+
|
|
72
|
+
for (BetaMessage message : toolRunner) {
|
|
73
|
+
System.out.println(message);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
See the [shared memory tool concepts](../../shared/tool-use-concepts.md) for more details on the memory tool.
|
|
78
|
+
|
|
79
|
+
### Non-Beta Tool Declaration (manual JSON schema)
|
|
80
|
+
|
|
81
|
+
`Tool.InputSchema.Properties` is a freeform `Map<String, JsonValue>` wrapper — build property schemas via `putAdditionalProperty`. `type: "object"` is the default. The builder has a direct `.addTool(Tool)` overload that wraps in `ToolUnion` automatically.
|
|
82
|
+
|
|
83
|
+
```java
|
|
84
|
+
import com.anthropic.core.JsonValue;
|
|
85
|
+
import com.anthropic.models.messages.Tool;
|
|
86
|
+
|
|
87
|
+
Tool tool = Tool.builder()
|
|
88
|
+
.name("get_weather")
|
|
89
|
+
.description("Get the current weather in a given location")
|
|
90
|
+
.inputSchema(Tool.InputSchema.builder()
|
|
91
|
+
.properties(Tool.InputSchema.Properties.builder()
|
|
92
|
+
.putAdditionalProperty("location", JsonValue.from(Map.of("type", "string")))
|
|
93
|
+
.build())
|
|
94
|
+
.required(List.of("location"))
|
|
95
|
+
.build())
|
|
96
|
+
.build();
|
|
97
|
+
|
|
98
|
+
MessageCreateParams params = MessageCreateParams.builder()
|
|
99
|
+
.model(Model.CLAUDE_SONNET_4_6)
|
|
100
|
+
.maxTokens(16000L)
|
|
101
|
+
.addTool(tool)
|
|
102
|
+
.addUserMessage("Weather in Paris?")
|
|
103
|
+
.build();
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
For manual tool loops, handle `tool_use` blocks in the response, send `tool_result` back, loop until `stop_reason` is `"end_turn"`. See [shared tool use concepts](../../shared/tool-use-concepts.md).
|
|
107
|
+
|
|
108
|
+
### Building `MessageParam` with Content Blocks (Tool Result Round-Trip)
|
|
109
|
+
|
|
110
|
+
`MessageParam.Content` is an inner union class (string | list). Use the builder's `.contentOfBlockParams(List<ContentBlockParam>)` alias — there is NO separate `MessageParamContent` class with a static `ofBlockParams`:
|
|
111
|
+
|
|
112
|
+
```java
|
|
113
|
+
import com.anthropic.models.messages.MessageParam;
|
|
114
|
+
import com.anthropic.models.messages.ContentBlockParam;
|
|
115
|
+
import com.anthropic.models.messages.ToolResultBlockParam;
|
|
116
|
+
|
|
117
|
+
List<ContentBlockParam> results = List.of(
|
|
118
|
+
ContentBlockParam.ofToolResult(ToolResultBlockParam.builder()
|
|
119
|
+
.toolUseId(toolUseBlock.id())
|
|
120
|
+
.content(yourResultString)
|
|
121
|
+
.build())
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
MessageParam toolResultMsg = MessageParam.builder()
|
|
125
|
+
.role(MessageParam.Role.USER)
|
|
126
|
+
.contentOfBlockParams(results) // builder alias for Content.ofBlockParams(...)
|
|
127
|
+
.build();
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Structured Output
|
|
133
|
+
|
|
134
|
+
The class-based overload auto-derives the JSON schema from your POJO and gives you a typed `.text()` return — no manual schema, no manual parsing.
|
|
135
|
+
|
|
136
|
+
```java
|
|
137
|
+
import com.anthropic.models.messages.StructuredMessageCreateParams;
|
|
138
|
+
|
|
139
|
+
record Book(String title, String author) {}
|
|
140
|
+
record BookList(List<Book> books) {}
|
|
141
|
+
|
|
142
|
+
StructuredMessageCreateParams<BookList> params = MessageCreateParams.builder()
|
|
143
|
+
.model(Model.CLAUDE_SONNET_4_6)
|
|
144
|
+
.maxTokens(16000L)
|
|
145
|
+
.outputConfig(BookList.class) // returns a typed builder
|
|
146
|
+
.addUserMessage("List 3 classic novels")
|
|
147
|
+
.build();
|
|
148
|
+
|
|
149
|
+
client.messages().create(params).content().stream()
|
|
150
|
+
.flatMap(cb -> cb.text().stream())
|
|
151
|
+
.forEach(typed -> {
|
|
152
|
+
// typed.text() returns BookList, not String
|
|
153
|
+
for (Book b : typed.text().books()) System.out.println(b.title());
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Supports Jackson annotations: `@JsonPropertyDescription`, `@JsonIgnore`, `@ArraySchema(minItems=...)`. Manual schema path: `OutputConfig.builder().format(JsonOutputFormat.builder().schema(...).build())`.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Anthropic-Defined Tools
|
|
162
|
+
|
|
163
|
+
Version-suffixed types; `name`/`type` auto-set by builder. Direct `.addTool()` overloads exist for most tool types; where one is missing (newer or less-common tools — see the advisor note below), wrap via the union type's static factory: `.addTool(BetaToolUnion.of<ToolName>(builder…build()))`. Web search and code execution are server-executed; bash and text editor are client-executed (you handle the `tool_use` locally — see `shared/tool-use-concepts.md`).
|
|
164
|
+
|
|
165
|
+
```java
|
|
166
|
+
import com.anthropic.models.messages.WebSearchTool20260209;
|
|
167
|
+
import com.anthropic.models.messages.ToolBash20250124;
|
|
168
|
+
import com.anthropic.models.messages.ToolTextEditor20250728;
|
|
169
|
+
import com.anthropic.models.messages.CodeExecutionTool20260120;
|
|
170
|
+
|
|
171
|
+
.addTool(WebSearchTool20260209.builder()
|
|
172
|
+
.maxUses(5L) // optional
|
|
173
|
+
.allowedDomains(List.of("example.com")) // optional
|
|
174
|
+
.build())
|
|
175
|
+
.addTool(ToolBash20250124.builder().build())
|
|
176
|
+
.addTool(ToolTextEditor20250728.builder().build())
|
|
177
|
+
.addTool(CodeExecutionTool20260120.builder().build())
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Also available: `WebFetchTool20260209`, `MemoryTool20250818`, `ToolSearchToolBm25_20251119`. For the advisor tool, use `BetaAdvisorTool20260301` in the beta namespace with `.addBeta("advisor-tool-2026-03-01")` (server-side; advisor model ≥ executor model). There is no direct `.addTool(BetaAdvisorTool20260301)` overload on the beta builder — wrap it via the `BetaToolUnion` static factory for the advisor type; if `javac` rejects the specific factory method name, `javap com.anthropic.models.beta.messages.BetaToolUnion | grep -i advisor` shows the exact one.
|
|
181
|
+
|
|
182
|
+
### Beta namespace (MCP, compaction)
|
|
183
|
+
|
|
184
|
+
For beta-only features use `com.anthropic.models.beta.messages.*` — class names have a `Beta` prefix AND live in the beta package. The beta `MessageCreateParams.Builder` has direct `.addTool(BetaToolBash20250124)` overloads AND `.addMcpServer()`:
|
|
185
|
+
|
|
186
|
+
```java
|
|
187
|
+
import com.anthropic.models.beta.messages.MessageCreateParams;
|
|
188
|
+
import com.anthropic.models.beta.messages.BetaToolBash20250124;
|
|
189
|
+
import com.anthropic.models.beta.messages.BetaCodeExecutionTool20260120;
|
|
190
|
+
import com.anthropic.models.beta.messages.BetaRequestMcpServerUrlDefinition;
|
|
191
|
+
|
|
192
|
+
MessageCreateParams params = MessageCreateParams.builder()
|
|
193
|
+
.model(Model.CLAUDE_OPUS_4_8)
|
|
194
|
+
.maxTokens(16000L)
|
|
195
|
+
.addBeta("mcp-client-2025-11-20")
|
|
196
|
+
.addTool(BetaToolBash20250124.builder().build())
|
|
197
|
+
.addTool(BetaCodeExecutionTool20260120.builder().build())
|
|
198
|
+
.addMcpServer(BetaRequestMcpServerUrlDefinition.builder()
|
|
199
|
+
.name("my-server")
|
|
200
|
+
.url("https://example.com/mcp")
|
|
201
|
+
.build())
|
|
202
|
+
.addUserMessage("...")
|
|
203
|
+
.build();
|
|
204
|
+
|
|
205
|
+
client.beta().messages().create(params);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`BetaTool*` types are NOT interchangeable with non-beta `Tool*` — pick one namespace per request.
|
|
209
|
+
|
|
210
|
+
**Reading server-tool blocks in the response:** `ServerToolUseBlock` has `.id()`, `.name()` (enum), and `._input()` returning raw `JsonValue` — there is NO typed `.input()`. For code execution results, unwrap two levels:
|
|
211
|
+
|
|
212
|
+
```java
|
|
213
|
+
for (ContentBlock block : response.content()) {
|
|
214
|
+
block.serverToolUse().ifPresent(stu -> {
|
|
215
|
+
System.out.println("tool: " + stu.name() + " input: " + stu._input());
|
|
216
|
+
});
|
|
217
|
+
block.codeExecutionToolResult().ifPresent(r -> {
|
|
218
|
+
r.content().resultBlock().ifPresent(result -> {
|
|
219
|
+
System.out.println("stdout: " + result.stdout());
|
|
220
|
+
System.out.println("stderr: " + result.stderr());
|
|
221
|
+
System.out.println("exit: " + result.returnCode());
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Streaming — Java
|
|
2
|
+
|
|
3
|
+
## Streaming
|
|
4
|
+
|
|
5
|
+
```java
|
|
6
|
+
import com.anthropic.core.http.StreamResponse;
|
|
7
|
+
import com.anthropic.models.messages.RawMessageStreamEvent;
|
|
8
|
+
|
|
9
|
+
MessageCreateParams params = MessageCreateParams.builder()
|
|
10
|
+
.model(Model.CLAUDE_OPUS_4_8)
|
|
11
|
+
.maxTokens(64000L)
|
|
12
|
+
.addUserMessage("Write a haiku")
|
|
13
|
+
.build();
|
|
14
|
+
|
|
15
|
+
try (StreamResponse<RawMessageStreamEvent> streamResponse = client.messages().createStreaming(params)) {
|
|
16
|
+
streamResponse.stream()
|
|
17
|
+
.flatMap(event -> event.contentBlockDelta().stream())
|
|
18
|
+
.flatMap(deltaEvent -> deltaEvent.delta().text().stream())
|
|
19
|
+
.forEach(textDelta -> System.out.print(textDelta.text()));
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
# Files API — Java
|
|
26
|
+
|
|
27
|
+
## Files API (Beta)
|
|
28
|
+
|
|
29
|
+
Under `client.beta().files()`. File references in messages need the beta message types (non-beta `DocumentBlockParam.Source` has no file-ID variant).
|
|
30
|
+
|
|
31
|
+
```java
|
|
32
|
+
import com.anthropic.models.beta.files.FileUploadParams;
|
|
33
|
+
import com.anthropic.models.beta.files.FileMetadata;
|
|
34
|
+
import com.anthropic.models.beta.messages.BetaRequestDocumentBlock;
|
|
35
|
+
import com.anthropic.models.beta.messages.BetaFileDocumentSource;
|
|
36
|
+
import java.nio.file.Paths;
|
|
37
|
+
|
|
38
|
+
FileMetadata meta = client.beta().files().upload(
|
|
39
|
+
FileUploadParams.builder()
|
|
40
|
+
.file(Paths.get("/path/to/doc.pdf")) // or .file(InputStream) or .file(byte[])
|
|
41
|
+
.build());
|
|
42
|
+
|
|
43
|
+
// Reference in a beta message:
|
|
44
|
+
BetaRequestDocumentBlock doc = BetaRequestDocumentBlock.builder()
|
|
45
|
+
.source(BetaFileDocumentSource.builder().fileId(meta.id()).build())
|
|
46
|
+
.build();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Other methods: `.list()`, `.delete(String fileId)`, `.download(String fileId)`, `.retrieveMetadata(String fileId)`.
|