{"id":28255584,"url":"https://github.com/brianium/oai-clj","last_synced_at":"2026-03-11T10:03:29.990Z","repository":{"id":293272748,"uuid":"983505844","full_name":"brianium/oai-clj","owner":"brianium","description":"A more Clojure friendly way to use openai-java","archived":false,"fork":false,"pushed_at":"2025-07-04T11:25:14.000Z","size":12510,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-01T15:41:39.264Z","etag":null,"topics":["clojure","openai"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brianium.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-14T13:34:47.000Z","updated_at":"2025-07-19T05:12:24.000Z","dependencies_parsed_at":"2025-05-14T14:54:55.396Z","dependency_job_id":"02c4b60b-9ba6-4ec2-9053-57c0b201bc52","html_url":"https://github.com/brianium/oai-clj","commit_stats":null,"previous_names":["brianium/oai-clj"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/brianium/oai-clj","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianium%2Foai-clj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianium%2Foai-clj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianium%2Foai-clj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianium%2Foai-clj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brianium","download_url":"https://codeload.github.com/brianium/oai-clj/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianium%2Foai-clj/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30377837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojure","openai"],"created_at":"2025-05-19T22:14:03.190Z","updated_at":"2026-03-11T10:03:29.985Z","avatar_url":"https://github.com/brianium.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oai-clj\n\n[![Clojars Project](https://img.shields.io/clojars/v/com.github.brianium/oai-clj.svg)](https://clojars.org/com.github.brianium/oai-clj)\n\nA no frills Clojure library on top of [openai-java](https://github.com/openai/openai-java)\n\n## Goals\n\n- Clojure maps over builders\n- Clojure maps over Java result types\n- Malli schemas for structured outputs\n- Keywords over enum types\n- Minimal syntactic sugar\n- Single import\n\n## Comparison\n\nA simple request to the Responses API\n\n```java\npackage com.openai.example;\n\nimport com.openai.client.OpenAIClient;\nimport com.openai.client.okhttp.OpenAIOkHttpClient;\nimport com.openai.models.ChatModel;\nimport com.openai.models.responses.ResponseCreateParams;\n\npublic final class ResponsesExample {\n    private ResponsesExample() {}\n\n    public static void main(String[] args) {\n        // Configures using one of:\n        // - The `OPENAI_API_KEY` environment variable\n        // - The `OPENAI_BASE_URL` and `AZURE_OPENAI_KEY` environment variables\n        OpenAIClient client = OpenAIOkHttpClient.fromEnv();\n\n        ResponseCreateParams createParams = ResponseCreateParams.builder()\n                .input(\"Tell me a story about building the best SDK!\")\n                .model(ChatModel.GPT_4O)\n                .build();\n\n        client.responses().create(createParams).output().stream()\n                .flatMap(item -\u003e item.message().stream())\n                .flatMap(message -\u003e message.content().stream())\n                .flatMap(content -\u003e content.outputText().stream())\n                .forEach(outputText -\u003e System.out.println(outputText.text()));\n    }\n}\n```\n\nAnd with Clojure:\n\n```clojure\n(require '[oai-clj.core :as oai])\n\n(def response\n  (oai/create-response :input \"Tell me a story about building the best SDK!\"))\n  \n(-\u003e (:output response)\n    (first)\n    (:message)\n    (:content)\n    (first)\n    (:output-text)\n    (:text))\n```\n\nOr image generation:\n\n```java\npackage com.openai.example;\n\nimport com.openai.client.OpenAIClient;\nimport com.openai.client.okhttp.OpenAIOkHttpClient;\nimport com.openai.models.images.ImageGenerateParams;\nimport com.openai.models.images.ImageModel;\nimport java.io.IOException;\n\npublic final class ImageGenerationExample {\n    private ImageGenerationExample() {}\n\n    public static void main(String[] args) throws IOException {\n        // Configures using one of:\n        // - The `OPENAI_API_KEY` environment variable\n        // - The `OPENAI_BASE_URL` and `AZURE_OPENAI_KEY` environment variables\n        OpenAIClient client = OpenAIOkHttpClient.fromEnv();\n\n        ImageGenerateParams imageGenerateParams = ImageGenerateParams.builder()\n                .responseFormat(ImageGenerateParams.ResponseFormat.URL)\n                .prompt(\"Two cats playing ping-pong\")\n                .model(ImageModel.DALL_E_2)\n                .size(ImageGenerateParams.Size._512X512)\n                .n(1)\n                .build();\n\n        client.images().generate(imageGenerateParams).data().orElseThrow().stream()\n                .flatMap(image -\u003e image.url().stream())\n                .forEach(System.out::println);\n    }\n}\n```\n\nWith clojure:\n\n```clojure\n(require '[oai-clj.core :as oai])\n\n(def image-response\n  (oai/generate-image\n    :prompt \"Two cats playing ping-pong\"\n    :model  :dall-e-2\n    :size   :512x512\n    :n 1))\n\n(:url (first (:data image-response)))\n```\n\n## Structured Outputs Via Malli\n\nDefine a schema in Malli and reference it by Var or a tuple. `:format` is a non-standard key and only meaningful to `oai-clj`.\n\n```clojure\n(def SumResult\n  [:map\n    [:result {:description \"The result of summing the numbers\"} :int]\n    [:joke {:description \"A relevant math joke because laughter is medicine\"} :string]])\n\n;;; Using a variable will automatically provide the variable name as the format name. This is the recommended method because it is the coolest\n(def response\n  (oai/create-response\n   :easy-input-messages [{:role :system :content \"Given 2 numbers, you add them together\"}\n                         {:role :user :content \"3 and 4 babbyyyyyy\"}]\n   :format 'SumResult))\n\n;;; You can also provide a tuple to give an explicit format name\n(def response\n  (oai/create-response\n   :easy-input-messages [{:role :system :content \"Given 2 numbers, you add them together\"}\n                         {:role :user :content \"3 and 4 babbyyyyyy\"}]\n   :format [SumResult \"CoolFormat\"]))\n```\n\nNote:\nIn addition to Malli schemas, plain Clojure maps are also supported for structured outputs. This is particularly useful when the schema is not known ahead of time - such as when a different LLM is generating the schema.\n\nHoping to apply the same support to tool use when that gets implemented.\n\n## General guidelines\n\nIn general, keyword names in Clojure will attempt a kebab cased keyword variant of the builder method. i.e `:file` will map to `(.file (TranscriptionCreateParams/builder))`.\nThe same is true for Java result types.\n\n`java.util.Optional` types are treated as such: the corresponding value in the map will just be `nil` if there is no value, otherwise it will have the appropriate value.\n\nSome \"extra\" keys are provided (mostly in the responses api) to make things a little easier for Clojurists. Look at the examples of using `create-response` with `:input-items` and `:easy-input-items`.\n\nSee [dev.clj](dev/dev.clj) for examples.\n\n## Customizing clients\n\nClients are pulled from dynamic vars set in `oai-clj.http`. The default behavior is to instantiate the the Java clients via env. This expects the `OPENAI_API_KEY` environment variable mentioned in Java docs. If further customization is needed, those dynamic vars can be overwritten.\n\n## Disclaimer\n\nSome things might not be supported, or could be more Clojure-y. Pull requests welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianium%2Foai-clj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrianium%2Foai-clj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianium%2Foai-clj/lists"}