A minimal CLI tool that turns natural language into instant APIs.
Project description
ask2api
ask2api is a minimal Python CLI tool that turns natural language prompts into structured API-style JSON responses using LLM.
It allows you to define a JSON Schema and force the model to answer strictly in that format.
Why ask2api?
Because LLMs are no longer just chatbots, they are also programmable API engines.
ask2api lets you use them that way. 🚀
Key features:
- Minimal dependencies
- CLI first
- Prompt → API behavior
- No markdown, no explanations, only valid JSON
- Vision modality support
- Designed for automation pipelines and AI-driven backend workflows
Installation
pip install ask2api
Set your OpenAI key:
export OPENAI_API_KEY="your_api_key"
Usage
Text-only prompts
Instead of asking:
"Where is the capital of France?"
and receiving free-form text, you can do this:
ask2api -p "Where is the capital of France?" -sf schema.json
And get a structured API response:
{
"country": "France",
"city": "Paris"
}
Vision modality
You can also analyze images and get structured JSON responses:
ask2api -p "Where is this place?" -sf schema.json -i https://upload.wikimedia.org/wikipedia/commons/6/64/Lesdeuxmagots.jpg
How it works
- You define the desired output structure using a JSON Schema.
- The schema is passed to the model using OpenAI's
json_schemastructured output format. - The system prompt enforces strict JSON-only responses.
- For vision tasks, images are automatically encoded (base64 for local files) or passed as URLs.
- The CLI prints the API-ready JSON output.
The model is treated as a deterministic API function.
Example schema
Create a file named schema.json:
{
"type": "object",
"properties": {
"country": { "type": "string" },
"city": { "type": "string" }
},
"required": ["country", "city"]
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ask2api-0.2.0.tar.gz.
File metadata
- Download URL: ask2api-0.2.0.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c38baad9b5cfad33dc23ea8b9bbea1a3c48f8344b1091966bba267ccbc6eb825
|
|
| MD5 |
508c1f0872a9bf09917ff7c905f15a5a
|
|
| BLAKE2b-256 |
e7a530bba1d2fe75186106c6e8168433203bd409adeda041aa0cc89e1c9892e4
|
File details
Details for the file ask2api-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ask2api-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5229d6b0a15508eb4a6edf35e6b0db293657aeede19ae3e3a48744bfd3972ed5
|
|
| MD5 |
da7140f2428c892b10b2bf536a5f3379
|
|
| BLAKE2b-256 |
d43eaed088fa42e1060cc59c004c9a3d6e3a528f5a5c5e3c4ec92350ce8519f6
|