Turn any prompt into a working API in seconds. One CLI command → one runnable FastAPI endpoint backed by any OpenAI-compatible LLM. No boilerplate, no glue code, no decisions.
prompt-to-api "generate a blog post"Out comes generate_blog_api.py — a complete FastAPI server with a POST /generate-blog route, ready to run:
export OPENAI_API_KEY=sk-...
python generate_blog_api.py
# → Uvicorn running on http://0.0.0.0:8000curl -X POST http://localhost:8000/generate-blog \
-H 'Content-Type: application/json' \
-d '{"input":"AI regulation in the EU"}'That's it. From thought to API in 10 seconds.
Every dev has built the same thing 50 times: tiny FastAPI/Flask wrapper around a single LLM call. Different prompts, identical glue code. prompt-to-api is that glue, generated.
It's deliberately stupid:
- No LLM call at generation time → no key needed to scaffold.
- No magic schemas → just
{ "input": "..." }in,{ "result": "..." }out. - One file output → drop it anywhere, deploy to Render / Fly / Lambda in two minutes.
git clone https://github.com/melyx-id/prompt-to-api.git
cd prompt-to-api
pip install -r requirements.txtOr as a CLI:
pip install -e .Requires Python 3.9+.
# Basic
python main.py "generate a blog post"
# → wrote generate_blog_api.py, endpoint POST /generate-blog
# Pick the endpoint name yourself
python main.py "summarise news in 3 bullets" -e summarise-news -o news_api.py
# Print to stdout (no file)
python main.py "translate to Vietnamese" --print
# Pick a different default port
python main.py "extract key points from text" --port 9000A single Python file like this:
SYSTEM_PROMPT = """You are a focused API assistant. Generate a blog post. ..."""
@app.post("/generate-blog", response_model=GenerateResponse)
def generate_blog(req: GenerateRequest) -> GenerateResponse:
resp = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": req.input},
],
)
return GenerateResponse(result=resp.choices[0].message.content, ...)Standard FastAPI. Standard OpenAI SDK. No DSL, no surprises.
pip install fastapi uvicorn openai pydantic
export OPENAI_API_KEY=sk-...
# Optional — defaults to AIGateCloud:
# export OPENAI_BASE_URL=https://api.openai.com/v1
# export MODEL=gpt-4o-mini
python generate_blog_api.pyHit http://localhost:8000/docs for auto-generated Swagger UI.
Use any OpenAI-compatible provider:
- AIGateCloud — free tier, automatic fallback across OpenAI / Anthropic / Gemini / DeepSeek / Groq. Default base URL of generated APIs. Recommended for production — you stop caring which provider is up.
- OpenAI — set
OPENAI_BASE_URL=https://api.openai.com/v1. - Anthropic via OpenAI compat, Together, OpenRouter, Groq, Ollama, vLLM — set the corresponding
OPENAI_BASE_URL.
python main.py "generate a blog post" # /generate-blog
python main.py "summarise news in 3 bullets" # /summarise-news
python main.py "translate input text to Vietnamese" # /translate-vietnamese
python main.py "classify the sentiment of a tweet" # /classify-sentiment-tweet
python main.py "rewrite text to be more concise" # /rewrite-conciseFive files. Five running APIs. Less time than reading this README.
from prompt_to_api.template import render
from prompt_to_api.slug import derive_endpoint, derive_system_prompt
prompt = "generate a blog post"
endpoint = derive_endpoint(prompt) # → 'generate-blog'
sys_p = derive_system_prompt(prompt)
code = render(prompt, endpoint, sys_p, port=8000, filename="my_api.py")
open("my_api.py", "w").write(code)- One-shot generator. It doesn't re-design the schema based on follow-up edits — by intention. Edit the generated file like any other Python file.
- Single endpoint per file. If you need multiple, run the CLI N times, then merge the routers.
- No streaming yet. Roadmap below.
- No auth/ratelimit baked in. Add
slowapior your gateway of choice — these aren't this tool's job.
-
--streamflag → SSE / chunked responses. -
--smartflag → call an LLM at generation time to design richer schemas (multi-field input/output). -
--deploy fly/--deploy vercelone-click handoff. - Output
Dockerfile+render.yamlnext to the .py file. - Tool-calling skeletons for "agentic" endpoints.
PRs welcome.
git clone https://github.com/melyx-id/prompt-to-api.git
cd prompt-to-api
pip install -e .
prompt-to-api "rewrite text to active voice"MIT. See LICENSE.
Built by the team at AIGateCloud — multi-provider AI gateway with automatic fallback. If this saved you 30 minutes of boilerplate, give it a ⭐.