Idiomatic Clojure wrapper over the official OpenAI Java SDK
(com.openai/openai-java), focused on the Responses API.
Idiomatic Clojure wrapper over the official OpenAI Java SDK (`com.openai/openai-java`), focused on the Responses API.
(cancel-response client response-id)Cancel an in-progress response by id and return the resulting response map.
Cancel an in-progress response by id and return the resulting response map.
(client)(client {:keys [api-key organization project base-url timeout-ms max-retries
azure-service-version]})An OpenAI client. With no args, resolves credentials from the environment
(OPENAI_API_KEY). Pass explicit config keys to set client options:
:api-key, :organization, :project, :base-url, :timeout-ms,
:max-retries, and :azure-service-version (an Azure OpenAI api-version
string, used together with an Azure :base-url).
An OpenAI client. With no args, resolves credentials from the environment (`OPENAI_API_KEY`). Pass explicit config keys to set client options: `:api-key`, `:organization`, `:project`, `:base-url`, `:timeout-ms`, `:max-retries`, and `:azure-service-version` (an Azure OpenAI api-version string, used together with an Azure `:base-url`).
(compact client response-id)Compact a previous response by id and return the compacted response map.
Compact a previous response by id and return the compacted response map.
(count-input-tokens client req)Count input tokens for a Responses request shape. Accepts the same request map
style as create-response; fields unsupported by the SDK's input token count
endpoint are ignored. Returns {:input-tokens n}.
Count input tokens for a Responses request shape. Accepts the same request map
style as `create-response`; fields unsupported by the SDK's input token count
endpoint are ignored. Returns `{:input-tokens n}`.(create-embeddings client req)Create embeddings for :input (a string, or a vector of strings) with
:model (required, e.g. "text-embedding-3-small"). Optional: :dimensions
(truncated output size, supported by v3 models) and :user.
Returns {:model "..." :embeddings [[floats ...] ...] :usage {:prompt-tokens n :total-tokens n}}; :embeddings is ordered to match the
input order (one vector even for string input).
Create embeddings for `:input` (a string, or a vector of strings) with
`:model` (required, e.g. "text-embedding-3-small"). Optional: `:dimensions`
(truncated output size, supported by v3 models) and `:user`.
Returns `{:model "..." :embeddings [[floats ...] ...] :usage
{:prompt-tokens n :total-tokens n}}`; `:embeddings` is ordered to match the
input order (one vector even for string input).(create-response client req)Send a Responses API request and return a Clojure map.
Request keys: :model (required string), :input (required string or vector),
:instructions, :max-output-tokens, :temperature, :top-p, :metadata,
:previous-response-id, :store, :reasoning, :user, :tools,
:tool-choice, :parallel-tool-calls, :background, :include,
:truncation, :prompt-cache-key, :safety-identifier, :service-tier,
:max-tool-calls, :top-logprobs, :json-schema, :verbosity,
:conversation, :stream-options, and :moderation.
Message-vector input items accept {:role :system|:developer|:user|:assistant :content "..."}, multimodal content vectors containing text, image, or file
part maps, and {:type :function-call-output :call-id "..." :output "..."}.
Map outputs are JSON-encoded.
Structured outputs: :json-schema {:name "..." :schema {...} :strict true :description "..."}.
Tools: {:type :function :name "..." :description "..." :strict true :parameters {...}}, {:type :web-search}, {:type :file-search :vector-store-ids [...]}, or {:type :code-interpreter :container "..."}.
Code interpreter defaults to an auto container when :container is omitted.
Tool choice: :auto, :required, :none, or {:type :function :name "..."}.
Returns {:id :model :status :output :text :usage :created-at} plus
:error, :incomplete-details, or :previous-response-id when present.
Output items are normalized to :message, :function-call, :reasoning,
:web-search-call, :file-search-call, :code-interpreter-call, or
:unknown.
Send a Responses API request and return a Clojure map.
Request keys: `:model` (required string), `:input` (required string or vector),
`:instructions`, `:max-output-tokens`, `:temperature`, `:top-p`, `:metadata`,
`:previous-response-id`, `:store`, `:reasoning`, `:user`, `:tools`,
`:tool-choice`, `:parallel-tool-calls`, `:background`, `:include`,
`:truncation`, `:prompt-cache-key`, `:safety-identifier`, `:service-tier`,
`:max-tool-calls`, `:top-logprobs`, `:json-schema`, `:verbosity`,
`:conversation`, `:stream-options`, and `:moderation`.
Message-vector input items accept `{:role :system|:developer|:user|:assistant
:content "..."}`, multimodal content vectors containing text, image, or file
part maps, and `{:type :function-call-output :call-id "..." :output "..."}`.
Map outputs are JSON-encoded.
Structured outputs: `:json-schema {:name "..." :schema {...} :strict true
:description "..."}`.
Tools: `{:type :function :name "..." :description "..." :strict true
:parameters {...}}`, `{:type :web-search}`, `{:type :file-search
:vector-store-ids [...]}`, or `{:type :code-interpreter :container "..."}`.
Code interpreter defaults to an auto container when `:container` is omitted.
Tool choice: `:auto`, `:required`, `:none`, or `{:type :function :name "..."}`.
Returns `{:id :model :status :output :text :usage :created-at}` plus
`:error`, `:incomplete-details`, or `:previous-response-id` when present.
Output items are normalized to `:message`, `:function-call`, `:reasoning`,
`:web-search-call`, `:file-search-call`, `:code-interpreter-call`, or
`:unknown`.(delete-response client response-id)Delete one stored response by id. The OpenAI Java SDK returns void.
Delete one stored response by id. The OpenAI Java SDK returns void.
(get-model client model-id)Retrieve one model by id as a {:id :created :owned-by} map.
Retrieve one model by id as a `{:id :created :owned-by}` map.
(get-response client response-id)Retrieve one stored response by id as a response map.
Retrieve one stored response by id as a response map.
(list-input-items client response-id)List input items for a stored response id as normalized maps. Pages are followed automatically.
List input items for a stored response id as normalized maps. Pages are followed automatically.
(list-models client)List available models as a vector of {:id :created :owned-by} maps. Pages
are followed automatically.
List available models as a vector of `{:id :created :owned-by}` maps. Pages
are followed automatically.(retrieve-streaming client response-id on-event)Resume streaming an existing background response id. Invokes on-event with
normalized event maps and returns concatenated output text, matching stream.
Resume streaming an existing background response id. Invokes `on-event` with normalized event maps and returns concatenated output text, matching `stream`.
(stream client req on-event)Stream a Responses API request, invoking on-event with a normalized event
map for every server-sent event as it arrives, and returning the concatenated
output text. Takes the same req map as create-response. The underlying
HTTP stream is closed automatically.
Stream a Responses API request, invoking `on-event` with a normalized event map for every server-sent event as it arrives, and returning the concatenated output text. Takes the same `req` map as `create-response`. The underlying HTTP stream is closed automatically.
(stream-text client req on-text)Stream a Responses API request, calling on-text with each output text delta
string as it arrives, and returning the full concatenated text.
Stream a Responses API request, calling `on-text` with each output text delta string as it arrives, and returning the full concatenated text.
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 |