Liking cljdoc? Tell your friends :D


A simple ChatGPT client for Clojure.


Clojars Project


(require '[clj-openai.core :as ai])

clj-openai provides 2 functions: completions and chat-completions. They both take config map as first argument. They both return string on success and error map on failure.



Function parameters:

  1. config map
  2. prompt string

Example usage:

(ai/completions {:api-key api-key, :base-url base-url}

Chat completions


Function parameters:

  1. config map
  2. vector of message objects

Example usage:

(ai/chat-completions {:api-key api-key, :base-url base-url}
                     [{:role "user", :content "hello"}])

Config map

Config map is passed as first argument to all provided functions. Available config keys:

  • :api-key - mandatory, managed here
  • :base-url - optional, defaults to



 {:message "Incorrect API key provided."
  :type "invalid_request_error"
  :param nil
  :code "invalid_api_key"}}


When introducing a new version, bump the version number in build.clj. After it's merged into master branch, create a git tag on the last commit and push the tag, it will trigger deploy to Clojars.

There are utility scripts in the bin/ directory for some common tasks:

  • ./bin/nrepl starts nREPL
  • ./bin/test runs all tests (accepts all -X arguments, docs)
  • ./bin/test-ns clj-openai.core-test runs tests in a single namespace
  • ./bin/test-var clj-openai.core-test/completion runs a single test
  • ./bin/lint runs kondo and eastwood
  • ./bin/coverage runs test coverage check
  • ./bin/ci run the project's CI pipeline and builds a jar
  • ./bin/local-install installs the jar into local maven repo
  • ./bin/deploy deploys the jar to clojars, CLOJARS_USERNAME and CLOJARS_PASSWORD env vars must be set


Copyright © 2023 Staifa

EPLv1.0 is just the default for projects generated by deps-new: you are not required to open source this project, nor are you required to use EPLv1.0! Feel free to remove or change the LICENSE file and remove or update this section of the file!

Distributed under the Eclipse Public License version 1.0.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close