> For the complete documentation index, see [llms.txt](https://ai2sql.gitbook.io/ai2sql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai2sql.gitbook.io/ai2sql/15.-ai2sql-api-integration.md).

# 15. AI2sql API Integration

Integrate SQL generation in your application with AI2sql's API, allowing you to transform natural language into SQL queries seamlessly.\
\
For information on API access and application, please visit the [website](https://www.ai2sql.io/enterprise-ai) for documentation and procedures.

```
Method: POST
Endpoint: https://web.ai2sql.io/api/1.1/wf/<BUSINESS_IDENTIFIER>
Authentication: Token <ACCESS_TOKEN>

Parameters:

prompt: A brief explanation of the data query you need.
model_version: Choose from sg-v1, sg-v2, sg-v3, sg-v4, or sg-v5. Default is sg-v1.
database_type: Supports one of these databases - MSSQL, MariaDB, Aurora, DynamoDB, or SQLite.
tables: An array of objects detailing your database schema.
tool: The tool parameter specifies the operation to perform: text2sql, optimizesql, 
explainsql
```

Replace `<BUSINESS_IDENTIFIER>` with the unique ID found in your AI2sql account dashboard URL.

Your `<ACCESS_TOKEN>` is available under Account Settings > API Access.

Choose from our simple or detailed schema structures based on your requirement.

**Example Use Case**

Suppose you want to query data from a table named `customers`. With AI2sql, you can simply describe your query, like "Get all customers who joined in the last month", and AI2sql will convert it into a corresponding SQL query.

```
curl -X POST 'https://web.ai2sql.io/api/1.1/wf/<BUSINESS_IDENTIFIER>' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Authorization: Bearer YOUR_BEARER_TOKEN' \
  -d 'user=YOUR_EMAIL_ADDRESS' \
  -d 'prompt=Get all customers who joined in the last month' \
  -d 'tables=customers(id, name, join_date)' \
  -d 'tool=text2sql'

```

### Utilizing AI2sql API After Adding Tables

After you have created and added tables to AI2sql, you can use the AI2sql API to interact with these tables efficiently. This powerful tool simplifies the process of querying and manipulating data in your database tables using natural language. For more detailed instructions on AI2sql tables and capabilities, refer to the AI2sql [documentation](/ai2sql/3.-managing-tables.md)

### Schema Mapping

This section should detail the mapping of natural language terms to their corresponding SQL tables, columns, and relationships in the database.  [This template](/ai2sql/16.-ai2sql-dictionary-template.md) can be customized for any database by filling in specific details related to the database schema, business rules, and terminology.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ai2sql.gitbook.io/ai2sql/15.-ai2sql-api-integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
