Liking cljdoc? Tell your friends :D

openai.core

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

cancel-batchclj

(cancel-batch client batch-id)

Cancel an in-progress batch by id and return the resulting batch map.

Cancel an in-progress batch by id and return the resulting batch map.
sourceraw docstring

cancel-responseclj

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

clientclj

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

compactclj

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

count-input-tokensclj

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

create-batchclj

(create-batch client req)

Create a batch job. Required: :input-file-id (an uploaded :batch-purpose JSONL file) and :endpoint (the API path string the batch targets, e.g. "/v1/responses", "/v1/chat/completions", or "/v1/embeddings"). Optional: :completion-window (defaults to "24h"), :metadata, and :output-expires-after {:seconds n}.

Returns {:id :status :endpoint :input-file-id :completion-window :created-at} plus :output-file-id, :error-file-id, :model, :completed-at, :failed-at, :expires-at, or :request-counts {:completed :failed :total} when present.

Create a batch job. Required: `:input-file-id` (an uploaded `:batch`-purpose
JSONL file) and `:endpoint` (the API path string the batch targets, e.g.
"/v1/responses", "/v1/chat/completions", or "/v1/embeddings").
Optional: `:completion-window` (defaults to "24h"), `:metadata`, and
`:output-expires-after {:seconds n}`.

Returns `{:id :status :endpoint :input-file-id :completion-window
:created-at}` plus `:output-file-id`, `:error-file-id`, `:model`,
`:completed-at`, `:failed-at`, `:expires-at`, or `:request-counts
{:completed :failed :total}` when present.
sourceraw docstring

create-embeddingsclj

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

create-responseclj

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

delete-fileclj

(delete-file client file-id)

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

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

delete-responseclj

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

file-contentclj

(file-content client file-id)

Download a file's content by id and return it as a byte array.

Download a file's content by id and return it as a byte array.
sourceraw docstring

get-batchclj

(get-batch client batch-id)

Retrieve one batch by id as a batch map.

Retrieve one batch by id as a batch map.
sourceraw docstring

get-fileclj

(get-file client file-id)

Retrieve one file's metadata by id as a file map.

Retrieve one file's metadata by id as a file map.
sourceraw docstring

get-modelclj

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

get-responseclj

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

list-batchesclj

(list-batches client)
(list-batches client opts)

List batches as a vector of batch maps. Optional keys: :after and :limit. Pages are followed automatically.

List batches as a vector of batch maps. Optional keys: `:after` and
`:limit`. Pages are followed automatically.
sourceraw docstring

list-filesclj

(list-files client)
(list-files client opts)

List files as a vector of file maps. Optional keys: :purpose, :order (:asc/:desc), :after, and :limit. Pages are followed automatically.

List files as a vector of file maps. Optional keys: `:purpose`, `:order`
(`:asc`/`:desc`), `:after`, and `:limit`. Pages are followed automatically.
sourceraw docstring

list-input-itemsclj

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

list-modelsclj

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

retrieve-streamingclj

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

streamclj

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

stream-textclj

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

upload-fileclj

(upload-file client req)

Upload a file. :file (required) is a java.nio.file.Path, a string path, a byte array, or an InputStream; :purpose (required) is e.g. :batch, :assistants, :fine-tune, :vision, :user-data, or :evals. Optional: :filename (used with byte-array/stream input) and :expires-after {:seconds n} (anchored to file creation time).

Returns {:id :bytes :created-at :filename :purpose :status} plus :expires-at/:status-details when present.

Upload a file. `:file` (required) is a `java.nio.file.Path`, a string path,
a byte array, or an `InputStream`; `:purpose` (required) is e.g. `:batch`,
`:assistants`, `:fine-tune`, `:vision`, `:user-data`, or `:evals`.
Optional: `:filename` (used with byte-array/stream input) and
`:expires-after {:seconds n}` (anchored to file creation time).

Returns `{:id :bytes :created-at :filename :purpose :status}` plus
`:expires-at`/`:status-details` when present.
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