This project is a Go-powered API server built with Gin and Go OpenAI that interacts with the OpenAI API, enabling seamless streaming of responses.
- Fast HTTP server using Gin
- Streamlined interaction with OpenAI API
- Real-time streaming of responses
- Go (version 1.21.x or higher)
- An active OpenAI API Key
git clone https://github.com/ctate/go-openai-api.git
cd go-openai-api
Before running the project, add an .env
file with these environment variable:
API_PORT="8080"
OPEN_API_KEY="your_openai_api_key"
To start the server:
go run .
By default, the server will start on http://localhost:8080
.
- POST
/chat
: Streams chat completions from OpenAI API
Here's a quick example using curl
to interact with the API:
curl -XPOST --no-buffer http://localhost:8080/chat -H "Content-Type: application/json" -d '{"prompt":"Lorem ipsum"}'
Contributions are welcome! Feel free to submit pull requests or create issues for bugs and feature requests.