Skip to content

Commit 23ac6ae

Browse files
sobychackospring-builds
authored andcommitted
Adding Anthropic Custom Skills Ref Docs
Signed-off-by: Soby Chacko <[email protected]> (cherry picked from commit ba49f4e)
1 parent d31dc3e commit 23ac6ae

File tree

1 file changed

+161
-9
lines changed

1 file changed

+161
-9
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/anthropic-chat.adoc

Lines changed: 161 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,26 +2023,178 @@ ChatResponse response = chatModel.call(
20232023
);
20242024
----
20252025

2026-
[NOTE]
2026+
=== Custom Skills
2027+
2028+
In addition to pre-built skills, Anthropic supports custom skills that you can create for specialized document templates, formatting rules, or domain-specific behaviors.
2029+
Custom skills are `SKILL.md` files with instructions that you upload to your Anthropic workspace.
2030+
Once uploaded, you can use them in Spring AI alongside pre-built skills.
2031+
2032+
Custom skills are ideal for:
2033+
2034+
* **Corporate branding**: Apply consistent headers, footers, logos, and color schemes
2035+
* **Compliance requirements**: Add required disclaimers, confidentiality notices, or audit trails
2036+
* **Document templates**: Enforce specific structures for reports, proposals, or specifications
2037+
* **Domain expertise**: Include industry-specific terminology, calculations, or formatting rules
2038+
2039+
For details on creating custom skills, refer to the https://platform.claude.com/docs/en/api/skills-guide[Anthropic Skills API documentation].
2040+
2041+
==== Uploading a Custom Skill
2042+
2043+
Upload your skill using the Anthropic API.
2044+
Note the specific format requirements for the `files[]` parameter:
2045+
2046+
[source,bash]
2047+
----
2048+
curl -X POST "https://api.anthropic.com/v1/skills" \
2049+
-H "x-api-key: $ANTHROPIC_API_KEY" \
2050+
-H "anthropic-version: 2023-06-01" \
2051+
-H "anthropic-beta: skills-2025-10-02" \
2052+
-F "display_title=My Custom Skill" \
2053+
-F "files[][email protected];filename=my-skill-name/SKILL.md"
2054+
----
2055+
2056+
[IMPORTANT]
20272057
====
2028-
*About Custom Skills*
2058+
* Use `files[]=` (with square brackets), not `files=`
2059+
* The `filename` parameter must include a directory matching the `name` field in your SKILL.md YAML frontmatter
2060+
* After uploading, verify your skill appears in the Anthropic Console under **Settings > Capabilities**
2061+
====
2062+
2063+
The response contains your skill ID:
2064+
2065+
[source,json]
2066+
----
2067+
{
2068+
"id": "skill_01AbCdEfGhIjKlMnOpQrStUv",
2069+
"display_title": "My Custom Skill",
2070+
"source": "custom",
2071+
"latest_version": "1765845644409101"
2072+
}
2073+
----
2074+
2075+
==== Using Custom Skills in Spring AI
2076+
2077+
Reference your custom skill by its ID using the `.customSkill()` method:
2078+
2079+
[source,java]
2080+
----
2081+
ChatResponse response = chatModel.call(
2082+
new Prompt(
2083+
"Create a quarterly sales report",
2084+
AnthropicChatOptions.builder()
2085+
.model("claude-sonnet-4-5")
2086+
.maxTokens(4096)
2087+
.customSkill("skill_01AbCdEfGhIjKlMnOpQrStUv")
2088+
.build()
2089+
)
2090+
);
2091+
----
2092+
2093+
==== Combining Pre-built and Custom Skills
20292094

2030-
In addition to the pre-built skills documented above, Anthropic supports custom skills that organizations can create for specialized document templates, formatting rules, or domain-specific behaviors.
2095+
You can use both pre-built and custom skills in the same request.
2096+
This allows you to leverage Anthropic's document generation capabilities while applying your organization's specific requirements:
2097+
2098+
[source,java]
2099+
----
2100+
ChatResponse response = chatModel.call(
2101+
new Prompt(
2102+
"Create a sales report spreadsheet",
2103+
AnthropicChatOptions.builder()
2104+
.model("claude-sonnet-4-5")
2105+
.maxTokens(4096)
2106+
.anthropicSkill(AnthropicApi.AnthropicSkill.XLSX) // Pre-built
2107+
.customSkill("skill_01AbCdEfGhIjKlMnOpQrStUv") // Your custom skill
2108+
.build()
2109+
)
2110+
);
2111+
----
20312112

2032-
**Important:** Custom skills must be created and uploaded through Anthropic's platform (Console or API) before they can be used.
2033-
Spring AI currently supports **using** custom skills once they are set up, but does not provide APIs for creating or managing custom skills.
2113+
==== Using SkillContainer with Custom Skills
20342114

2035-
If you have custom skills configured in your Anthropic workspace, you can reference them by their skill ID:
2115+
For more control over skill versions, use `SkillContainer` directly:
20362116

20372117
[source,java]
20382118
----
20392119
AnthropicApi.SkillContainer container = AnthropicApi.SkillContainer.builder()
2040-
.customSkill("skill_abc123") // Your custom skill ID from Anthropic
2120+
.anthropicSkill(AnthropicApi.AnthropicSkill.XLSX)
2121+
.customSkill("skill_01AbCdEfGhIjKlMnOpQrStUv") // Uses latest version
2122+
.customSkill("skill_02XyZaBcDeFgHiJkLmNoPq", "1765845644409101") // Specific version
20412123
.build();
2124+
2125+
ChatResponse response = chatModel.call(
2126+
new Prompt(
2127+
"Generate the report",
2128+
AnthropicChatOptions.builder()
2129+
.model("claude-sonnet-4-5")
2130+
.maxTokens(8192)
2131+
.skillContainer(container)
2132+
.build()
2133+
)
2134+
);
20422135
----
20432136

2044-
Refer to the https://platform.claude.com/docs/en/build-with-claude/skills-guide[Anthropic Skills API documentation] for details on creating and managing custom skills in your workspace.
2045-
====
2137+
==== Updating a Custom Skill
2138+
2139+
To update an existing skill, upload a new version to the `/versions` endpoint:
2140+
2141+
[source,bash]
2142+
----
2143+
curl -X POST "https://api.anthropic.com/v1/skills/YOUR_SKILL_ID/versions" \
2144+
-H "x-api-key: $ANTHROPIC_API_KEY" \
2145+
-H "anthropic-version: 2023-06-01" \
2146+
-H "anthropic-beta: skills-2025-10-02" \
2147+
-F "files[][email protected];filename=my-skill-name/SKILL.md"
2148+
----
2149+
2150+
When using `latest` as the version (the default), the new version is picked up automatically.
2151+
2152+
==== Complete Custom Skills Example
2153+
2154+
Here's a complete example showing a service that optionally applies a custom branding skill:
2155+
2156+
[source,java]
2157+
----
2158+
@Service
2159+
public class BrandedDocumentService {
2160+
2161+
private static final String BRANDING_SKILL_ID = "skill_01AbCdEfGhIjKlMnOpQrStUv";
2162+
2163+
private final AnthropicChatModel chatModel;
2164+
private final AnthropicApi anthropicApi;
2165+
2166+
public BrandedDocumentService(AnthropicChatModel chatModel, AnthropicApi anthropicApi) {
2167+
this.chatModel = chatModel;
2168+
this.anthropicApi = anthropicApi;
2169+
}
2170+
2171+
public byte[] generateReport(String prompt, boolean includeBranding) throws IOException {
2172+
// Build options with document skill
2173+
AnthropicChatOptions.Builder optionsBuilder = AnthropicChatOptions.builder()
2174+
.model("claude-sonnet-4-5")
2175+
.maxTokens(8192)
2176+
.anthropicSkill(AnthropicApi.AnthropicSkill.XLSX);
2177+
2178+
// Add custom branding skill if requested
2179+
if (includeBranding) {
2180+
optionsBuilder.customSkill(BRANDING_SKILL_ID);
2181+
}
2182+
2183+
ChatResponse response = chatModel.call(
2184+
new Prompt(prompt, optionsBuilder.build())
2185+
);
2186+
2187+
// Extract and download the generated file
2188+
List<String> fileIds = SkillsResponseHelper.extractFileIds(response);
2189+
2190+
if (fileIds.isEmpty()) {
2191+
throw new RuntimeException("No file was generated");
2192+
}
2193+
2194+
return anthropicApi.downloadFile(fileIds.get(0));
2195+
}
2196+
}
2197+
----
20462198

20472199
== Sample Controller
20482200

0 commit comments

Comments
 (0)