A lightweight, production-ready Generative AI microservice built in Go. This service exposes a simple, prompt-driven API for generating text using an LLM, designed to act as a foundational building block in a larger AI backend system.
This service intentionally focuses on generation only — it does not perform retrieval, orchestration, evaluation, or task-specific transformations. Those responsibilities live in other services.
This service exists to provide a clean, reusable interface for text generation, suitable for:
- Explanations and drafting
- General-purpose completions
- Backend-driven AI features
- Use by RAG pipelines, workflows, or automation tools
It reflects how production AI backends typically isolate LLM access behind a dedicated service.
- Prompt-driven (no hard-coded task assumptions)
- Produces new text, not transformations
- Provider-agnostic via an LLM client interface
- Reusable across many contexts
Client
|
| POST /generate
v
Generative AI Service
|
|-- LLM Client Interface
|
|-- OpenAI (real)
|-- Mock (local/testing)
The HTTP layer is completely decoupled from the LLM provider.
Generates text based on a prompt and optional system context.
{
"system": "You are a helpful backend tutor.",
"prompt": "Explain pgvector in simple terms.",
"max_tokens": 300,
"temperature": 0.7
}{
"output": "pgvector is a Postgres extension that allows...",
"model": "gpt-4o-mini",
"tokens_used": 279,
"request_id": "fc2c9a9e-e950-4526-a3f0-05994b5dc44e"
}Environment variables:
PORT=8080
OPENAI_API_KEY=your_api_key_here
OPENAI_MODEL=gpt-4o-mini
LLM_MODE=real # or mockreal→ Uses OpenAImock→ Returns deterministic mock output (no API calls)
LLM_MODE=mock go run .curl -X POST http://localhost:8080/generate \
-H "Content-Type: application/json" \
-d '{"prompt":"Explain pgvector simply"}'LLM_MODE=real OPENAI_API_KEY=sk-... go run .This service is designed to be called by other services, including:
- RAG pipelines (for answer generation)
- Workflow / orchestration services
- Automation tools (n8n, Zapier, internal systems)
It intentionally avoids embedding higher-level logic so it remains composable and reusable.
- Go
- Fiber v2
- OpenAI API
- Docker
- Fly.io (deployment)
- Clear responsibility boundaries
- Simple, inspectable APIs
- Provider abstraction
- Production-minded defaults
- Easy to rebuild from memory
- Streaming responses
- Model switching
- Prompt templates
- Usage metrics
- Centralized AI gateway
This project prioritizes clarity and correctness over complexity. It represents how generative AI is typically exposed in real backend systems — as a focused service that other components build upon.