Skip to content

melyx-id/prompt-to-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prompt-to-api

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.

Python 3.9+ License: MIT Powered by AIGateCloud


The 30-second pitch

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:8000
curl -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.

Why this exists

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.

Install

git clone https://github.com/melyx-id/prompt-to-api.git
cd prompt-to-api
pip install -r requirements.txt

Or as a CLI:

pip install -e .

Requires Python 3.9+.

Usage

# 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 9000

What gets generated

A 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.

Run the generated API

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.py

Hit http://localhost:8000/docs for auto-generated Swagger UI.

Where to get a key

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.

Demo: 5 endpoints, 5 commands

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-concise

Five files. Five running APIs. Less time than reading this README.

Programmatic use

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)

Honest caveats

  • 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 slowapi or your gateway of choice — these aren't this tool's job.

Roadmap

  • --stream flag → SSE / chunked responses.
  • --smart flag → call an LLM at generation time to design richer schemas (multi-field input/output).
  • --deploy fly / --deploy vercel one-click handoff.
  • Output Dockerfile + render.yaml next to the .py file.
  • Tool-calling skeletons for "agentic" endpoints.

PRs welcome.

Contributing

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"

License

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 ⭐.

About

Turn any prompt into a working API in seconds. FastAPI + any OpenAI-compatible LLM.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages