{"id":15069045,"url":"https://github.com/sigpwned/openai4j","last_synced_at":"2026-01-30T16:53:03.336Z","repository":{"id":187265348,"uuid":"676591889","full_name":"sigpwned/openai4j","owner":"sigpwned","description":"OpenAI client for Java","archived":false,"fork":false,"pushed_at":"2024-03-25T21:34:57.000Z","size":161,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-06T18:50:04.518Z","etag":null,"topics":["java","java-11","openai","openai-api"],"latest_commit_sha":null,"homepage":"https://github.com/sigpwned/openai4j","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sigpwned.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-09T14:51:49.000Z","updated_at":"2023-08-09T15:07:39.000Z","dependencies_parsed_at":"2024-02-22T00:25:46.969Z","dependency_job_id":"916e7e09-9675-4df9-8e29-3d3cccd53365","html_url":"https://github.com/sigpwned/openai4j","commit_stats":null,"previous_names":["sigpwned/openai4j"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/sigpwned/openai4j","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fopenai4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fopenai4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fopenai4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fopenai4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sigpwned","download_url":"https://codeload.github.com/sigpwned/openai4j/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fopenai4j/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28915938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T16:37:38.804Z","status":"ssl_error","status_checked_at":"2026-01-30T16:37:37.878Z","response_time":66,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["java","java-11","openai","openai-api"],"created_at":"2024-09-25T01:40:10.560Z","updated_at":"2026-01-30T16:53:03.314Z","avatar_url":"https://github.com/sigpwned.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# OPENAI4J [![tests](https://github.com/sigpwned/openai4j/actions/workflows/tests.yml/badge.svg)](https://github.com/sigpwned/openai4j/actions/workflows/tests.yml)\n\nOpenAI4j is an [OpenAI API](https://openai.com/blog/openai-api) client for Java 11 or later. It is generated from the [OpenAI API OpenAPI spec](https://github.com/openai/openai-openapi) using the excellent [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator), which is why this repo is (mostly) empty except for a POM and OpenAPI spec.\n\n## Goals\n\n* To provide an easy-to-use Java client for the OpenAI API\n* To stay in sync with the OpenAI API as changes are made\n* To minimize maintenance effort by generating code\n* To require a minimum of dependencies\n\n## Non-Goals\n\n* To support the API spec as written, since it requires changes to generate valid Java code\n* No dependencies\n\n## Versioning\n\nThe versioning of this project followers the versioning of [the OpenAI OpenAPI spec](https://github.com/openai/openai-openapi), with a fourth component of format `yyyymmdd` representing the release date. While this *looks* like [SemVer](https://semver.org/), OpenAI does not seem to manage the versioning of its OpenAPI spec according to semver, so users should test before upgrading.\n\n## Edits from Original File\n\nThe OpenAI OpenAPI spec is a poor fit for Java, as written. Therefore, this project makes some systematic changes to the OpenAPI spec before generating code. The spec used for code generation is can be found at `openapi.yml` in this repo.\n\n### Type Adjustments\n\nThe OpenAPI spec is clearly intended for dynamically-typed languages. Overall, the OpenAPI Generator does a truly heroic job of generating sane types. However, typing like this is very hard for explicitly-typed languages to handle:\n\n    prompt:\n      description: \u0026completions_prompt_description |\n        The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays.\n\n        Note that \u003c|endoftext|\u003e is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document.\n      default: \"\u003c|endoftext|\u003e\"\n      nullable: true\n      oneOf:\n        - type: string\n          default: \"\"\n          example: \"This is a test.\"\n        - type: array\n          items:\n            type: string\n            default: \"\"\n            example: \"This is a test.\"\n        - type: array\n          minItems: 1\n          items:\n            type: integer\n          example: \"[1212, 318, 257, 1332, 13]\"\n        - type: array\n          minItems: 1\n          items:\n            type: array\n            minItems: 1\n            items:\n              type: integer\n          example: \"[[1212, 318, 257, 1332, 13]]\"\n\nWhich type should prompt have?\n\n* `String`\n* `String[]`\n* `int[]`\n* `int[][]`\n\nThis is further complicated by the presence of a default value, which is a string.\n\nAs a result, this project applies the following typing changes to the original OpenAPI spec:\n\n- For `oneOf` types with a combination of different scalar types or scalar and array types, the string type is preferred.\n- For `oneOf` types witha  combination of string type and object or array types, the string type is preferred.\n- For `anyOf` types with a string and an enum, the string type is preferred.\n\nThe OpenAPI Generator (surprisingly, and laudably) manages the following types well enough that they are left alone:\n\n- `oneOf` types with a choice between multiple object types\n\n## Example Code\n\n### Generate a chat completion\n\nThe following code generates a chat completion using the model `gpt-3.5-turbo-1106`:\n\n    public String generateChatResponse(ChatApi chat, String userPrompt) {\n        List\u003cChatCompletionRequestMessage\u003e messages = new ArrayList\u003c\u003e();\n        if (getSystemInstructions() != null)\n          messages.add(new ChatCompletionRequestMessage(new ChatCompletionRequestSystemMessage()\n              .role(ChatCompletionRequestSystemMessage.RoleEnum.SYSTEM)\n              .content(\"You are a helpful assistant.\")));\n        messages.add(new ChatCompletionRequestMessage(\n            new ChatCompletionRequestUserMessage().role(ChatCompletionRequestUserMessage.RoleEnum.USER)\n                .content(userPrompt)));\n    \n        CreateChatCompletionResponse response=chat.createChatCompletion(\n              new CreateChatCompletionRequest().model(\"gpt-3.5-turbo-1106\").messages(messages).n(1));\n    \n        CreateChatCompletionResponseChoicesInner choice = response.getChoices().get(0);\n    \n        return choice.getMessage().getContent();\n    }\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigpwned%2Fopenai4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigpwned%2Fopenai4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigpwned%2Fopenai4j/lists"}