Liking cljdoc? Tell your friends :D

anthropic.core

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.
raw docstring

batch-resultsclj

(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.
sourceraw docstring

cancel-batchclj

(cancel-batch client id)

Request cancellation of a batch; returns the updated batch map.

Request cancellation of a batch; returns the updated batch map.
sourceraw docstring

clientclj

(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.
sourceraw docstring

count-tokensclj

(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}`.
sourceraw docstring

create-batchclj

(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`).
sourceraw docstring

create-messageclj

(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 {...}}`.
sourceraw docstring

delete-batchclj

(delete-batch client id)

Delete a batch by id. Returns {:id ... :deleted true}.

Delete a batch by id. Returns `{:id ... :deleted true}`.
sourceraw docstring

delete-fileclj

(delete-file client id)

Delete a file by id. Returns {:id ... :deleted true}.

Delete a file by id. Returns `{:id ... :deleted true}`.
sourceraw docstring

download-fileclj

(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.
sourceraw docstring

get-batchclj

(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.
sourceraw docstring

get-fileclj

(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.
sourceraw docstring

get-modelclj

(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.
sourceraw docstring

list-batchesclj

(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`.
sourceraw docstring

list-filesclj

(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`.
sourceraw docstring

list-modelsclj

(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.
sourceraw docstring

streamclj

(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`).
sourceraw docstring

stream-textclj

(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.
sourceraw docstring

upload-fileclj

(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.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close