# yaml-language-server: $schema=../../tools/ai-codegen/codegen.schema.json
# Pinned to anthropic-sdk-typescript sdk-v0.135.0 (2026-10-15). To update, pin the latest release
# commit and regenerate from the repo root:
# nix develop -c node packages/tools/ai-codegen/src/bin.ts generate --provider anthropic
spec: https://raw.githubusercontent.com/anthropics/anthropic-sdk-typescript/04a4c28c70de498d6d0e930e43edb5edb9ac545e/scripts/mock-spec.json.gz
output: src/Generated.ts
# Generate the public API only; the bundled spec also covers admin and managed-agent endpoints.
includePaths:
- /v1/complete
- /v1/files
- /v1/messages
- /v1/models
- /v1/skills
name: AnthropicClient
patches:
# Upstream reuses released Skills names for reshaped schemas. Move the current wire schemas to
# *Resource names, and point the operations at them, so the released contracts below keep their names.
- patches/current-skills.json
# Released Skills contracts, before upstream renamed and reshaped them. Copied verbatim from the
# spec generated on 2026-02-20 (anthropic-sdk-typescript fdaa72bed1). Regenerate with:
# curl -sL 'https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-29a6b7ba51942cd606e5bf4b533e5aac1bef42f6d4b1f7f45f756304cf676782.yml' \
# | jq '[.components.schemas | to_entries[] | select(.key | test("^(Beta)?((Create|Get|Delete)Skill(Version)?Response|api__schemas__skills__Skill|Skill(Version)?|List(Skills|SkillVersions)Response)$")) | {op: "add", path: "/components/schemas/\(.key)", value: .value}]' \
# > packages/ai/anthropic/patches/legacy-skills.json
- patches/legacy-skills.json
# Keep usage fields optional when the API or Anthropic-compatible gateways omit them (#8464, #9963).
- '[{"op":"replace","path":"/components/schemas/BetaUsage/required","value":["input_tokens","output_tokens"]},{"op":"replace","path":"/components/schemas/Usage/required","value":["cache_creation","cache_creation_input_tokens","cache_read_input_tokens","input_tokens","output_tokens","service_tier"]},{"op":"replace","path":"/components/schemas/BetaMessageDeltaUsage/required","value":["output_tokens"]},{"op":"replace","path":"/components/schemas/MessageDeltaUsage/required","value":["cache_creation_input_tokens","cache_read_input_tokens","input_tokens","output_tokens"]}]'
# Keep message metadata optional when the API omits it.
- '[{"op":"replace","path":"/components/schemas/BetaMessage/required","value":["id","type","role","content","model","stop_reason","stop_sequence","usage"]},{"op":"replace","path":"/components/schemas/Message/required","value":["id","type","role","content","model","stop_reason","stop_sequence","usage","container"]},{"op":"replace","path":"/components/schemas/BetaMessageDeltaEvent/required","value":["delta","type","usage"]},{"op":"replace","path":"/components/schemas/BetaMessageDelta/required","value":["stop_reason","stop_sequence"]}]'
# Keep fields added since the released schemas optional, so responses without them still decode
# (the thinking token estimate needs a beta header; older API versions and gateways omit the rest).
- '[{"op":"replace","path":"/components/schemas/BetaThinkingContentBlockDelta/required","value":["thinking","type"]},{"op":"replace","path":"/components/schemas/BetaCompactionContentBlockDelta/required","value":["content","type"]},{"op":"replace","path":"/components/schemas/BetaResponseCompactionBlock/required","value":["content","type"]},{"op":"replace","path":"/components/schemas/ModelInfo/required","value":["created_at","display_name","id","type"]},{"op":"replace","path":"/components/schemas/BetaModelInfo/required","value":["created_at","display_name","id","type"]},{"op":"replace","path":"/components/schemas/Container/required","value":["expires_at","id"]},{"op":"replace","path":"/components/schemas/MessageDelta/required","value":["container","stop_reason","stop_sequence"]}]'
# Make citations optional in text blocks (API may omit this field).
- '[{"op":"replace","path":"/components/schemas/ResponseTextBlock/required","value":["text","type"]},{"op":"replace","path":"/components/schemas/BetaResponseTextBlock/required","value":["text","type"]}]'
# Make model optional in BetaMessageIterationUsage (gateways and older responses may omit it)
- '[{"op":"replace","path":"/components/schemas/BetaMessageIterationUsage/required","value":["cache_creation","cache_creation_input_tokens","cache_read_input_tokens","input_tokens","output_tokens","type"]}]'
# Decode every error envelope and let the status code decide the error, as released.
collapseErrorResponses: true
# Released schemas that no operation references: stream events, batch results, memory tool
# commands, multipart bodies, and the deprecated Skills contracts patched in above.
includeSchemas:
- BetaContentBlockDeltaEvent
- BetaContentBlockStartEvent
- BetaContentBlockStopEvent
- BetaMessageDeltaEvent
- BetaMessageStartEvent
- BetaMessageStopEvent
- ContentBlockDeltaEvent
- ContentBlockStartEvent
- ContentBlockStopEvent
- MessageDeltaEvent
- MessageStartEvent
- MessageStopEvent
- CitationsDelta
- InputJsonContentBlockDelta
- MessageDelta
- SignatureContentBlockDelta
- TextContentBlockDelta
- ThinkingContentBlockDelta
- BetaCanceledResult
- BetaErroredResult
- BetaExpiredResult
- BetaSucceededResult
- CanceledResult
- ErroredResult
- ExpiredResult
- SucceededResult
- BetaMemoryTool_20250818_CreateCommand
- BetaMemoryTool_20250818_DeleteCommand
- BetaMemoryTool_20250818_InsertCommand
- BetaMemoryTool_20250818_RenameCommand
- BetaMemoryTool_20250818_StrReplaceCommand
- BetaMemoryTool_20250818_ViewCommand
- BetaBody_create_skill_v1_skills_post
- BetaBody_create_skill_version_v1_skills__skill_id__versions_post
- Body_create_skill_v1_skills_post
- Body_create_skill_version_v1_skills__skill_id__versions_post
- Betaapi__schemas__skills__Skill
- BetaCreateSkillResponse
- BetaCreateSkillVersionResponse
- BetaDeleteSkillResponse
- BetaDeleteSkillVersionResponse
- BetaGetSkillResponse
- BetaGetSkillVersionResponse
- CreateSkillResponse
- CreateSkillVersionResponse
- DeleteSkillResponse
- DeleteSkillVersionResponse
- GetSkillResponse
- GetSkillVersionResponse
- Skill
- SkillVersion
- BetaSkill
- BetaSkillVersion
- ListSkillsResponse
- ListSkillVersionsResponse
- BetaListSkillsResponse
- BetaListSkillVersionsResponse
header: |
/**
* @stability unstable
* @since 4.0.0
*/
excludeAnnotations:
- examples
disableAdditionalProperties: true
replacements:
# Schema.Unknown doesn't work with Schema.toCodecJson (used by HttpClientResponse.schemaBodyJson)
# Replace with Schema.Json which properly handles arbitrary JSON values
- from: "Schema.Record(Schema.String, Schema.Unknown)"
to: "Schema.Record(Schema.String, Schema.Json)"
- from: "{ readonly [x: string]: unknown }"
to: "{ readonly [x: string]: Schema.Json }"
# Index signature in struct rest pattern
- from: "readonly [x: string]: unknown"
to: "readonly [x: string]: Schema.Json"
# Keep the released types: tool input examples accept any value, and beta headers accept a string
- from: "export type BetaJsonValue = Schema.Json"
to: "export type BetaJsonValue = unknown"
- from: 'export const BetaJsonValue = Schema.Json.annotate({ "expected": "JSON value", "identifier": "BetaJsonValue" })'
to: "export const BetaJsonValue = Schema.Unknown"
- from: "export type JsonValue = Schema.Json"
to: "export type JsonValue = unknown"
- from: 'export const JsonValue = Schema.Json.annotate({ "expected": "JSON value", "identifier": "JsonValue" })'
to: "export const JsonValue = Schema.Unknown"
- from: 'readonly "anthropic-beta"?: ReadonlyArray<AnthropicBeta>'
to: 'readonly "anthropic-beta"?: string | ReadonlyArray<AnthropicBeta>'
- from: '"anthropic-beta": Schema.optionalKey(Schema.Array(AnthropicBeta).annotate('
to: '"anthropic-beta": Schema.optionalKey(Schema.Union([Schema.String, Schema.Array(AnthropicBeta)]).annotate('