Chat with Agent

Here’s the enhanced API Reference for “Chat with Agent”, including detailed behavior, cURL requests, and JavaScript (fetch) code examples.


💬 Chat with Agent (Natural Language to SQL)

These endpoints allow users to query their PostgreSQL database using text or voice. The API:

  • Interprets natural language

  • Generates SQL

  • Executes queries on the provided database

  • Returns results, refined answers, and even voice responses.


🔸 POST /chat – Query Database with Natural Language

Converts a plain-text prompt into SQL, executes it on the linked PostgreSQL database, and returns results.


📥 Request Body:

{
  "db_url": "postgresql://user:pass@host:5432/dbname",
  "prompt": "Show me the total revenue for Q1"
}

🔐 Auth Required: ✅ Yes (JWT required)

📤 Response:


✅ Behavior:

  • Detects database schema automatically

  • Uses a reusable SQL “tool” if matched

  • Fills placeholders (e.g., Q1, 2023, etc.)

  • Executes query

  • Returns refined natural-language response


✅ cURL Example


✅ JS (fetch) Example


🔸 POST /audio-chat – Voice-to-SQL Agent

Accepts audio input (or text) and returns both:

  • Text result

  • Base64-encoded audio response


📥 Form-Data Fields:

Field
Type
Required
Description

audio

file

optional

WAV/MP3 file of your voice

text

string

optional

Text fallback if no audio

🔐 Auth Required: ✅ Yes


📤 Response:


✅ Voice Flow:

  1. Audio is transcribed via ElevenLabs STT

  2. Prompt is run through the /chat engine

  3. Final response is converted back to voice (TTS)

  4. Both text + base64 voice are returned


✅ cURL Example (with text only)

✅ JS Example (text-only query)


✅ JS Example (with audio file)


🔄 Ideal Use Cases:

  • Integrate into business dashboards

  • Enable “Ask your data” voice/chat in SaaS apps

  • Embed SQL reasoning in analytics tools


Let me know when you're ready to move on to: 🎙 Voice Services (STT & TTS) APIs.

Last updated