Skip to main content

A minimal CLI tool that turns natural language into instant APIs.

Project description

ask2api

CI PyPI version Python 3.9+ License: MIT

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 API key:

export ASK2API_API_KEY="your_api_key"
# Or you can pass 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

Or pass an example directly without a schema file:

ask2api -p "Where is the capital of France?" -e '{"country": "string", "city": "string"}'

And get a structured API response:

{
  "country": "France",
  "city": "Paris"
}
For more complex structures with different data types:
ask2api -p "Analyze carbon element" -e '{
  "symbol": "element symbol",
  "atomic_number": 1234,
  "atomic_weight": 12.34,
  "is_metal": true,
  "isotopes": ["name of the isotope"],
  "properties": {
    "melting_point": 1234.5,
    "boiling_point": 2345.6,
    "magnetic": true
  }
}'

Output:

{
  "symbol": "C",
  "atomic_number": 6,
  "atomic_weight": 12.011,
  "is_metal": false,
  "isotopes": [
    "C-12",
    "C-13",
    "C-14"
  ],
  "properties": {
    "melting_point": 3550,
    "boiling_point": 4827,
    "magnetic": false
  }
}

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

  1. You define the desired output structure using a JSON Schema.
  2. The schema is passed to the model using OpenAI's json_schema structured output format.
  3. The system prompt enforces strict JSON-only responses.
  4. For vision tasks, images are automatically encoded (base64 for local files) or passed as URLs.
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ask2api-1.1.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ask2api-1.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file ask2api-1.1.0.tar.gz.

File metadata

  • Download URL: ask2api-1.1.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ask2api-1.1.0.tar.gz
Algorithm Hash digest
SHA256 1af3357eabd86d364e755ae4caf4474c69bbfec6b60fcaf3f56b5cace5681341
MD5 6c88e69fbc52c88e40dacc86b66c10e9
BLAKE2b-256 afd04fde28f1c94b3a190594a6b42b788969b3f624d6ea7cfed25e654a1908ee

See more details on using hashes here.

File details

Details for the file ask2api-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: ask2api-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ask2api-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c2bac0e3542787ac886ad23963aa3cef2530efd7cbbf9cab9b749a94d88561a
MD5 8ce8d9e68b88ebefedbb805f9a68ccb7
BLAKE2b-256 6f5aa309dab86c4d41537483c6e22f21caa6c87606af8c0abb67099013d90865

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page