Skip to main content

Generative AI

Kvery integrates OpenAI models so you can write and understand SQL faster. The AI SQL assistant in the editor can draft a query from a plain-language request, explain an existing query, fix an error or suggest optimizations, and Kvery can generate a description for a query — all from inside the editor.

Open the assistant with AI chat above the SQL editor, to the right of the Query label. The link is shown when Kvery can read the database structure of the query's connection; while the connection is unavailable, the editor says so, and autocomplete and the assistant are not available.

Bring your own key​

The AI features use your own OpenAI API key. You add it once on your profile (see OpenAI key); Kvery then calls OpenAI on your behalf and the usage is billed to your OpenAI account. Without a key, AI chat and Generate AI open your profile on the OpenAI tab with the message "To use AI features, please add your OpenAI API key.".

Available models​

You pick the model on the OpenAI tab of your profile. Prices are OpenAI's rates in USD per 1 million tokens; repeated parts of a request (such as the database schema in a longer chat) are often billed at the lower cached input rate.

Name in KveryModelInputCached inputOutput
GPT-6 Astra (most capable)gpt-6-astra$10.00$1.00$50.00
GPT-6.1 Sol (recommended)gpt-6.1-sol$2.00$0.10$10.00
GPT-6 Luna (fast, low cost)gpt-6-luna$0.10$0.01$0.50
GPT-5.6 Solgpt-5.6-sol$4.00$0.40$20.00
GPT-5.6 Terragpt-5.6-terra$2.00$0.20$12.00
GPT-5.6 Luna (fast)gpt-5.6-luna$0.20$0.02$1.20
o3 (legacy)o3$2.00$0.50$8.00
GPT-5 mini (legacy)gpt-5-mini$0.25$0.025$2.00
GPT-5 (legacy)gpt-5$1.25$0.125$10.00

Pick the recommended model for everyday work, the fast, low cost one for quick iterations, and the most capable one when a query is genuinely complex. Pricing may change on OpenAI's side. The chat shows the tokens used and the estimated cost of the session.

What the assistant can do​

  • Generate SQL from a natural-language description of what you want. SQL answers can be applied to the editor with one click.
  • Explain an existing query so you understand it before running it.
  • Fix a query that returns an error, and suggest optimizations.
  • Generate a description to keep your workspace documented: Generate AI, to the right of the query's Description label, asks the AI for a short title and a one-sentence explanation of the SQL in the editor (an empty editor shows "The editor is empty. Please write a SQL query first."). The Review AI suggestions window shows the old and the new texts, and you can edit the new ones. Accept under Description copies the title into the Description field, which is stored with your next save; Accept under Internal note — shown to users who can write the query's internal note — saves the explanation as the internal note right away. Both texts are written in the language of the Kvery application. If the editor does not hold SQL, Kvery shows the AI's explanation as an error message instead of the window.

The assistant answers either with a complete SQL statement or with a plain-text answer; text answers come in the language of your last message. It uses the current SQL in the editor as context (untick Use current SQL as context to switch this off), and it works in the SQL dialect of the query's connection.

Using the chat​

The AI SQL Assistant window leaves the editor usable behind it.

  • Press Enter to send a message and Shift+Enter for a new line; Stop cancels an answer that is still pending. If a request fails, your message goes back into the input box.
  • The pencil next to one of your messages puts its text back into the box (Editing message; Cancel edit or Esc leaves it). When you send a changed text, Kvery asks whether to delete the later messages and get a new reply (OK) or only replace the text of the message (Cancel).
  • Apply to editor under a SQL answer replaces the SQL in the editor with the answer, formatted, and updates the query's form.
  • Clear chat empties the conversation and its token and cost counter. The conversation is kept only while the page is open: reloading the page or opening another query starts a new one.

Database schema as context​

To write correct SQL, the assistant gets your database structure as context: the names of the tables and columns, the column types and the comments (system schemas such as information_schema are left out). Smaller schemas are sent completely; larger ones are reduced to the tables relevant to the conversation and the SQL, up to about 60,000 characters. A structure of more than about 10 MB is not used at all: the assistant then answers without it.

What is sent to OpenAI​

For the chat, Kvery sends the SQL dialect of the connection, the database structure described above, the SQL of the editor (while Use current SQL as context is ticked) and the chat messages. For a generated description it sends the SQL of the editor and the database structure. Query results are never sent. Each request carries a pseudonymous identifier derived from your account, not your name or e-mail address.

How requests are bounded​

To keep requests efficient and predictable, Kvery caps each AI interaction:

  • Up to 8,000 completion tokens per chat response and 2,000 for a generated description. Reasoning models think before they answer, and their reasoning tokens count towards the same limit.
  • The conversation history forwarded to OpenAI is limited to 20 user/assistant turn pairs and 50,000 characters in total; longer back-and-forths simply forget the oldest turns.
  • The SQL sent with a request can be up to 100,000 characters (a longer one is refused with "The SQL or message is too long for the AI assistant."); a single chat message is cut to 20,000 characters.
  • Each user can send up to 30 AI requests per minute (chat, description generation and saving the OpenAI settings together); above that the answer is "Rate limit exceeded. Try again later.".
  • A request has about 90 seconds to complete; temporary OpenAI errors are retried automatically within that time. When no answer has arrived after about 100 seconds, the browser stops waiting with "Request timed out. Please try a simpler query or try again later.".
  • A request larger than the per-minute token limit of your OpenAI account, or longer than the selected model accepts, is refused with a message that says which limit it hit and what to do (in the chat: clear the chat or ask about fewer tables).

If an answer runs out of its token budget, Kvery tells you so — ask a more specific question or about fewer tables.

Tips​

  • Give the assistant context — table and column names, what you're trying to achieve — for better SQL.
  • Always review generated SQL before running it, especially write statements.
  • Use drafts to test AI-generated changes safely before publishing.
  • Clear the chat when you switch topics: a shorter history is faster and cheaper.