> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Integration

> Configure AI chat, LaTeX error suggestions, quotas and search services on a Kubernetes deployment.

The AI assistant and the LaTeX error assistant run in the **web** service (the `workbench` and `error-assistant` modules) of every Ayakaleaf Pro pod. What each setting does, user access and quotas are described in [AI Integration](https://ayakaleaf-pro.mintlify.site/on-premises/configuration/overleaf-toolkit/integrations/ai-integration.md); this page puts it into Kubernetes.

| | |
| - | - |
| Service | web, in every Ayakaleaf Pro pod; read when web starts. The `web_fetch` tool goes through linked-url-proxy in the same pod |
| Pod → outside | `AI_BASE_URL`; `WEB_SEARCH_URL` (default `https://api.tavily.com/search`) and `DOCS_MCP_URL` if search is on; pages the model reads with `web_fetch` |
| Outside → Overleaf | none |
| State | the token quota counters in Redis, shared by all replicas; the chat history stays in the browser |
| Periodic jobs | none |

### Configuration

**1. ConfigMap**

```yaml title="30-config.yaml (additions)" wrap theme={null}
  AI_ENABLED: "true"
  AI_BASE_URL: https://ai-gateway.example.com/v1
  AI_MODEL: YOUR_TEXT_MODEL_ID
  # optional, see the Toolkit page
  # AI_IMAGE_MODEL: YOUR_IMAGE_CAPABLE_MODEL_ID
  # AI_PDF_MODEL: YOUR_PDF_CAPABLE_MODEL_ID
  # AI_TOKEN_QUOTA: "200000"
  # AI_TOKEN_QUOTA_PERIOD: month
  # AI_PROXY_URL: http://proxy.example.com:3128
```

`AI_ENABLED` must be exactly `"true"`. The assistant appears only when `AI_ENABLED`, `AI_BASE_URL`, `AI_MODEL` and `AI_API_KEY` are all set.

**2. Secret**

```bash theme={null}
kubectl -n overleaf patch secret overleaf-secrets --type merge -p '{"stringData":{
  "AI_API_KEY":"<gateway key>",
  "TAVILY_API_KEY":"<search key, optional>"}}'
```

**3. Apply, restart and check the gateway from every pod**

```bash theme={null}
kubectl apply -f 30-config.yaml
kubectl -n overleaf rollout restart deployment/overleaf     # or statefulset/overleaf
for p in $(kubectl -n overleaf get pod -l app=overleaf -o name); do   # app=overleaf-ha for several replicas
  kubectl -n overleaf exec "$p" -- curl -sS -o /dev/null -w "$p %{http_code}\n" https://ai-gateway.example.com/v1/models
done
```

Any HTTP status means the gateway is reachable; `000` means it is not.

The `web_fetch` tool fetches pages through the same proxy as [External URL](https://ayakaleaf-pro.mintlify.site/on-premises/configuration/kubernetes/external-url.md) files, so the `OVERLEAF_LINKED_URL_*` settings also limit what the model may read.

### Several replicas

Nothing extra. The token quota is counted in Redis, so a user's usage is the same on every replica, and an admin's reset applies everywhere.

### Tested on Kubernetes

Against a mock of an OpenAI-compatible gateway, Tavily and the GitBook MCP endpoint (trusted through `NODE_EXTRA_CA_CERTS` from `overleaf-certs`), on Kubernetes 1.37, our end-to-end tests pass: for the AI assistant on three replicas behind HAProxy (31 cases), chats with tool calls and suggested edits, web and documentation search, reading web pages through linked-url-proxy limited by `OVERLEAF_LINKED_URL_ALLOWED_RESOURCES`, image and PDF attachments, consent, the token quota counted in Redis, AI turned off for a user and for the instance, and slow connections to the gateway; for the error assistant on one replica (15 cases), suggested fixes, consent, the shared token quota and AI turned off.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.