This project is a secure, production-ready integration with the OpenAI API, built using Java 21 and Spring Boot. It provides a clean and extensible service for interacting with ChatGPT models via HTTP.
- 🔐 Encrypted API key support via Jasypt
- 📡 Connects to OpenAI Chat Completion endpoint
- 🧪 Integration test to verify external API connectivity
- 🧰 Configuration via
application.properties - ✅ CI-ready with GitHub Actions
- Java 21
- Maven 3.8+
- OpenAI API Key (use environment secret or Jasypt)
All sensitive configuration is encrypted using Jasypt.
openai.api.url=https://api.openai.com/v1/chat/completions
openai.api.model=gpt-3.5-turbo
openai.api.key=ENC(ENCRYPTED_KEY_HERE)
jasypt.encryptor.algorithm=PBEWithMD5AndTripleDESThe Jasypt password must be provided via:
-
VM Option:
-Djasypt.encryptor.password=your-secret -
Or GitHub Actions secret:
JASYPT_PASSWORD
Inject the service:
@Autowired
private OpenAiService openAiService;
String reply = openAiService.chat("Hello, how are you?");
System.out.println(reply);A test class (OpenAiApiConnectivityTest) ensures that the application can reach OpenAI and receive a valid response.
Run it with:
mvn test -Djasypt.encryptor.password=your-secretThis project includes a GitHub Actions workflow that:
- Builds and tests your app on push/pull requests
- Uses secrets to pass the Jasypt password securely
Secrets required:
| Name | Description |
|---|---|
JASYPT_PASSWORD |
Password to decrypt your API key |
src
├── main
│ └── java/org/abosk/openaiclient
│ ├── config
│ ├── service
│ └── controller
├── test
│ └── java/org/abosk/openaiclient/integration
└── resources
└── application.properties
This project is open-source and available under the MIT License.