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

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"
}

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. 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-0.1.0.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

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

ask2api-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ask2api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d1984bbd349f0d7b0ddb2a3a4f1f11dfba6822b29601d8944054a65e0e7b74f
MD5 d43b5ed6d8628aed2ae3b844f93a2121
BLAKE2b-256 a4803ba557b3ea099a9c27536f2f2b62dec7557d2e59bac88a496be450567917

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ask2api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4674cf283fa47fa3142e760f40052deb9087617f389471f20341086c996b99f5
MD5 60110413fc8f01231170bcc4a15e0a5d
BLAKE2b-256 43b8acf6074a356dbdc56032225f7cd18e8cd46dca185d770d53eae33cb62f54

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