# AI Assistant (/docs/guides/ai-assistant)

Generate, explain, and fix SQL with a hosted provider such as Groq, OpenAI, Anthropic, or Gemini, or a local Ollama model, with your keys encrypted at rest.

Dora's AI assistant helps you write SQL from a description, explain an existing
query, fix an error, or suggest indexes, with the connected schema as context.
It works with a hosted provider (with an API key) or a fully local model.

## Providers [#providers]

| Provider  | Needs an API key? | Runs locally? |
| --------- | ----------------- | ------------- |
| Groq      | Yes               | No            |
| OpenAI    | Yes               | No            |
| Anthropic | Yes               | No            |
| Gemini    | Yes               | No            |
| DeepSeek  | Yes               | No            |
| Kimi      | Yes               | No            |
| GLM       | Yes               | No            |
| Qwen      | Yes               | No            |
| OpenRouter | Yes              | No            |
| Ollama    | No                | Yes           |

**Groq is the default**, using `llama-3.3-70b-versatile`, which is fast and has a generous
free tier.

## Configure a provider [#configure-a-provider]

Open **Settings → AI Keys**, pick a provider, and add a key. You can name a key,
**Test** it, and choose a model. Alternatively, set the matching environment
variable before launching Dora and it is picked up automatically (a key saved in
the app takes precedence):

| Provider  | Environment variable |
| --------- | -------------------- |
| Groq      | `GROQ_API_KEY`       |
| OpenAI    | `OPENAI_API_KEY`     |
| Anthropic | `ANTHROPIC_API_KEY`  |
| Gemini    | `GEMINI_API_KEY`     |
| DeepSeek  | `DEEPSEEK_API_KEY`   |
| Kimi      | `KIMI_API_KEY`       |
| GLM       | `GLM_API_KEY`        |
| Qwen      | `QWEN_API_KEY`       |
| OpenRouter | `OPENROUTER_API_KEY` |

<Callout type='info'>
	Keys are encrypted at rest with AES-256-GCM; the master key lives in your OS keychain. See
	[Credentials & security](/docs/guides/security).
</Callout>

## Run models locally with Ollama [#run-models-locally-with-ollama]

[Ollama](https://ollama.com) runs models on your machine: no API key, and no
data leaves your computer.

1. Install Ollama (Dora can detect it and guide a managed install from
   **Settings → Local models**).
2. Start it and pull a model: `ollama pull llama3.2`.
3. Select **Ollama** as the provider. The default model is `llama3.2`.

Dora's built-in Ollama manager shows whether the server is running, lists and
pulls models with live progress, and removes models you no longer need.

## Use it [#use-it]

Open the assistant from its item in the navigation sidebar, or with
`Mod+Shift+B`. It opens as a panel beside the grid or console. From the
[SQL Console](/docs/guides/sql-console) or [Data Studio](/docs/guides/data-studio),
ask it to:

- **generate**: "find users who haven't logged in for 30 days",
- **explain**: paste a query and ask what it does,
- **fix**: share a failing query and its error,
- **optimize**: ask which indexes would help a query.

If a message fails to send, Dora puts your prompt back in the input so you can
send it again.

## Hide AI [#hide-ai]

Turn on **Settings → Safety → Hide AI** to remove every AI entry point: the
assistant panel and its sidebar item, `Mod+I` generation in the SQL Console, the
explain and fix actions, and the AI sections in settings. It is off by default.
