AI SQL API

Beta features are available to users before official release. Your testing and feedback are an enormous help, please leave any feedback or bug reports you have at support@logicloop.com. Note that beta features are subject to change.

LogicLoop's AI SQL capabilities are available via API if you wish to use AI to generate SQL in your own application. First, if you haven't already created a LogicLoop account you can do so here.

Generate SQL based on a natural language request

You can call our SQL generation endpoint in order to generate SQL based on a user request.

Method: POST
URL: https://app.logicloop.com/<YOUR_COMPANY_SLUG>/api/v1/ai/query_generate 
Authorization: Key <YOUR_API_KEY>
Params:
    prompt: A description of the data you're looking for
    model: One of oa-v1, oa-v2, oa-v2-16k, oa-v3 or ant-v1. Defaults to oa-v1.
    data_source_type: One of postgres, mysql, redshift, snowflake, big_query or oracle
    data_schema: A list of dictionaries representing your data schema

Be sure to replace <YOUR_COMPANY_SLUG> which you can find by logging into your dashboard and looking at the URL:

You can find <YOUR API_KEY> by going to Settings > Users > click on your profile > copy the API Key.

You can use either the basic or advanced data schema format below depending on the level of granularity you are looking for.

Data schema format (basic):

[
	{
		"table_name": "table_1",
		"columns": [
			{"name": "col_1"},
			{"name": "col_2"},
			{"name": "col_3"}
		]
	},
	{
		"table_name": "table_2",
		"columns": [
			{"name": "col_1"},
			{"name": "col_2"},
			{"name": "col_3"}
		]
	}
]

Example:

[
	{
		"table_name": "users",
		"columns": [
			{"name": "name"},
			{"name": "id"},
			{"name": "email"}
		]
	},
	{
		"table_name": "orders",
		"columns": [
			{"name": "product"},
			{"name": "id"},
			{"name": "amount"},
			{"name": "status"}
		]
	}
]

Data schema format (advanced):

[
	{
		"table_name": "table_1",
		"columns": [
			{
				"name": "col_1",
				"type": "type_1",
				"description": "description_1",
				"constraint": "primary key"
			},
			{
				"name": "col_2",
				"type": "type_2",
				"description": "description_2"
			},
			{
				"name": "col_3",
				"type": "type_3",
				"description": "description_3"
			}
		]
	},
	{
		"table_name": "table_2",
		"columns": [
			{
				"name": "col_1",
				"type": "type_1",
				"description": "description_1",
				"constraint": "primary key"
			},
			{
				"name": "col_2",
				"type": "type_2",
				"description": "description_2",
				"constraint": "foreign key references table_1(col_1)"
			},
			{
				"name": "col_3",
				"type": "type_3",
				"description": "description_3"
			}
		]
	}
]

Example:

[
	{
		"table_name": "users",
		"columns": [
			{
				"name": "name",
				"type": "string",
				"description": "The users given name"
			},
			{
				"name": "id",
				"type": "int",
				"description": "The users unique identifier",
				"constraint": "primary key"
			},
			{
				"name": "email",
				"type": "string",
				"description": "The users contact email address"
			}
		]
	},
	{
		"table_name": "orders",
		"columns": [
			{
				"name": "id",
				"type": "int",
				"description": "The orders unique identifier",
				"constraint": "primary key"
			},
			{
				"name": "user_id",
				"type": "int",
				"description": "The id of the user who this order belongs to",
				"constraint": "foreign key references users(id)"
			},
			{
				"name": "amount",
				"type": "int",
				"description": "The total price of the order in USD"
			},
			{
				"name": "status",
				"type": "enum(canceled, pending, completed)",
				"description": "The shipping status of this order"
			}
		]
	}
]

Sample CURL request

curl -X POST https://app.logicloop.com//api/v1/ai/query_generate -H "Authorization: Key <YOUR_API_KEY>" -d '{"prompt":"Help me find invalid emails","data_source_type":"postgres", "data_schema": [{"table_name": "users", "columns": [{"name": "name"}, {"name": "id"}, {"name": "email"}]}]}' 

Response

{"query_response":"SELECT name, id, email\nFROM users\nWHERE email NOT LIKE '%@%.%';\n"}

Last updated