Idiomatic Clojure wrapper over the official Anthropic Java SDK
(com.anthropic/anthropic-java).
Build a request as a Clojure map, get a Clojure map back. The client reads
ANTHROPIC_API_KEY from the environment by default.
Idiomatic Clojure wrapper over the official Anthropic Java SDK (`com.anthropic/anthropic-java`). Build a request as a Clojure map, get a Clojure map back. The client reads `ANTHROPIC_API_KEY` from the environment by default.
(batch-results client id)Fetch a completed batch's results as a vector of
{:custom-id ... :result {:type :succeeded|:errored|:canceled|:expired ...}};
succeeded results include the parsed :message. The results stream is closed
automatically.
Fetch a completed batch's results as a vector of
`{:custom-id ... :result {:type :succeeded|:errored|:canceled|:expired ...}}`;
succeeded results include the parsed `:message`. The results stream is closed
automatically.(cancel-batch client id)Request cancellation of a batch; returns the updated batch map.
Request cancellation of a batch; returns the updated batch map.
(client)(client {:keys [api-key]})An Anthropic client. With no args, resolves credentials from the environment
(ANTHROPIC_API_KEY). Pass {:api-key "..."} to set the key explicitly.
An Anthropic client. With no args, resolves credentials from the environment
(`ANTHROPIC_API_KEY`). Pass `{:api-key "..."}` to set the key explicitly.(count-tokens client req)Count the input tokens a request would use, without sending it. Takes the same
req map as create-message (sampling params and :max-tokens are ignored).
Returns {:input-tokens n}.
Count the input tokens a request would use, without sending it. Takes the same
`req` map as `create-message` (sampling params and `:max-tokens` are ignored).
Returns `{:input-tokens n}`.(create-batch client requests)Submit a Message Batch. requests is a seq of
{:custom-id "..." :params <same map as create-message>} (:params ignores
:service-tier). Returns the batch as a map (see get-batch).
Submit a Message Batch. `requests` is a seq of
`{:custom-id "..." :params <same map as create-message>}` (`:params` ignores
`:service-tier`). Returns the batch as a map (see `get-batch`).(create-message client req)Send a Messages request and return the response as a Clojure map.
req keys: :model (string, defaults to "claude-opus-4-8"), :max-tokens
(defaults to 1024), :system (string), :messages (a seq of
{:role :user|:assistant :content "..."}), :tools, and the optional
controls :temperature, :top-p, :top-k, :stop-sequences (seq of
strings), :tool-choice (:auto/:any/:none or {:type :tool :name "x"}),
:thinking ({:type :enabled :budget-tokens N} / {:type :adaptive} /
{:type :disabled}), :metadata ({:user-id "..."}), and :service-tier
(:auto/:standard-only). For structured output, pass :response-format (a
JSON Schema map) and/or :effort (:low…:max); when :response-format is
set the returned map also carries :parsed, the response text decoded as a
Clojure map. Returns
{:id :model :role :stop-reason :content [...] :usage {...}}.
Send a Messages request and return the response as a Clojure map.
`req` keys: `:model` (string, defaults to "claude-opus-4-8"), `:max-tokens`
(defaults to 1024), `:system` (string), `:messages` (a seq of
`{:role :user|:assistant :content "..."}`), `:tools`, and the optional
controls `:temperature`, `:top-p`, `:top-k`, `:stop-sequences` (seq of
strings), `:tool-choice` (`:auto`/`:any`/`:none` or `{:type :tool :name "x"}`),
`:thinking` (`{:type :enabled :budget-tokens N}` / `{:type :adaptive}` /
`{:type :disabled}`), `:metadata` (`{:user-id "..."}`), and `:service-tier`
(`:auto`/`:standard-only`). For structured output, pass `:response-format` (a
JSON Schema map) and/or `:effort` (`:low`…`:max`); when `:response-format` is
set the returned map also carries `:parsed`, the response text decoded as a
Clojure map. Returns
`{:id :model :role :stop-reason :content [...] :usage {...}}`.(delete-batch client id)Delete a batch by id. Returns {:id ... :deleted true}.
Delete a batch by id. Returns `{:id ... :deleted true}`.
(delete-file client id)Delete a file by id. Returns {:id ... :deleted true}.
Delete a file by id. Returns `{:id ... :deleted true}`.
(download-file client id)Download a file's contents by id, returning a byte array. The HTTP response is closed automatically.
Download a file's contents by id, returning a byte array. The HTTP response is closed automatically.
(get-batch client id)Retrieve a batch by id. Returns {:id :processing-status :request-counts :created-at :expires-at} plus :ended-at/:results-url once available.
Retrieve a batch by id. Returns `{:id :processing-status :request-counts
:created-at :expires-at}` plus `:ended-at`/`:results-url` once available.(get-file client id)Retrieve a file's metadata by id: {:id :filename :mime-type :size-bytes :created-at} plus :downloadable when reported.
Retrieve a file's metadata by id: `{:id :filename :mime-type :size-bytes
:created-at}` plus `:downloadable` when reported.(get-model client id)Retrieve one model's info by id, as a map shaped like list-models' entries.
Retrieve one model's info by id, as a map shaped like `list-models`' entries.
(list-batches client)List all batches (pages followed) as a seq of maps like get-batch.
List all batches (pages followed) as a seq of maps like `get-batch`.
(list-files client)List uploaded files (pages followed) as a seq of maps like get-file.
List uploaded files (pages followed) as a seq of maps like `get-file`.
(list-models client)List the available models as a seq of maps, newest first. Each map has :id,
:display-name, :created-at (ISO-8601 string), and :max-input-tokens /
:max-tokens when the API reports them. Pages are followed automatically.
List the available models as a seq of maps, newest first. Each map has `:id`, `:display-name`, `:created-at` (ISO-8601 string), and `:max-input-tokens` / `:max-tokens` when the API reports them. Pages are followed automatically.
(stream client req on-event)Stream a Messages request, invoking on-event with a normalized event map for
every server-sent event as it arrives, and returning the full concatenated
assistant text when the stream ends. Takes the same req map as
create-message. The underlying HTTP stream is closed automatically.
Event maps are keyed by :type: :message-start, :content-block-start
(:index, :block), :text-delta/:thinking-delta/:input-json-delta/
:signature-delta (:index plus the payload), :content-block-stop
(:index), :message-delta (:stop-reason), and :message-stop. To
reconstruct a streamed tool call, accumulate :input-json-delta :partial-json
per :index (the matching :content-block-start carries the tool :id/:name).
Stream a Messages request, invoking `on-event` with a normalized event map for every server-sent event as it arrives, and returning the full concatenated assistant text when the stream ends. Takes the same `req` map as `create-message`. The underlying HTTP stream is closed automatically. Event maps are keyed by `:type`: `:message-start`, `:content-block-start` (`:index`, `:block`), `:text-delta`/`:thinking-delta`/`:input-json-delta`/ `:signature-delta` (`:index` plus the payload), `:content-block-stop` (`:index`), `:message-delta` (`:stop-reason`), and `:message-stop`. To reconstruct a streamed tool call, accumulate `:input-json-delta` `:partial-json` per `:index` (the matching `:content-block-start` carries the tool `:id`/`:name`).
(stream-text client req on-text)Stream a Messages request, calling on-text with each text delta (a string)
as it arrives, and returning the full concatenated text when the stream ends.
Takes the same req map as create-message. A thin convenience over stream
that ignores every non-text event; reach for stream when you need thinking or
tool-use deltas. The underlying HTTP stream is closed automatically.
Stream a Messages request, calling `on-text` with each text delta (a string) as it arrives, and returning the full concatenated text when the stream ends. Takes the same `req` map as `create-message`. A thin convenience over `stream` that ignores every non-text event; reach for `stream` when you need thinking or tool-use deltas. The underlying HTTP stream is closed automatically.
(upload-file client file)Upload a file (a path string, java.io.File, java.nio.file.Path,
InputStream, or byte array) to the Files API. Returns its metadata map
(see get-file). Uses the beta Files API.
Upload a file (a path string, `java.io.File`, `java.nio.file.Path`, `InputStream`, or byte array) to the Files API. Returns its metadata map (see `get-file`). Uses the beta Files API.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |