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

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-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). 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`). Returns
`{:id :model :role :stop-reason :content [...] :usage {...}}`.
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

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