# Use Xantly with n8n

[n8n](https://n8n.io) is the open-source workflow automation tool, connect services, trigger on events, run AI inside workflows. Its **OpenAI Chat Model** node accepts a custom base URL, so pointing it at Xantly gives every workflow BaRP routing, semantic cache, and memory. The **AI Agent** node (LangChain under the hood) also picks up the same config.

## Prerequisites

- n8n running (self-hosted, cloud, or desktop)
- A Xantly API key, [create one](/dashboard/api-keys)

## Setup

1. In n8n, go to **Credentials** → **Add Credential** → **OpenAI API**.
2. Fill in:

| Field | Value |
|---|---|
| Name | `Xantly` |
| API Key | `xantly_sk_...` |
| Base URL | `https://api.xantly.com/v1` |
| Organization ID | *(leave blank)* |

3. Click **Save**.

Now every node that uses the OpenAI credential, **OpenAI Chat Model**, **AI Agent**, **Chain LLM**, **OpenAI**: routes through Xantly.

## Simple Chat Model node

1. Add an **OpenAI Chat Model** node.
2. Under **Credential for OpenAI API**, pick `Xantly`.
3. Set **Model** to `xantly/auto-quality` (or any catalog slug).
4. Wire up input messages.

Run the workflow, Xantly logs the call with routing + cost.

## AI Agent (LangChain) node

The **AI Agent** node is a LangChain agent under the hood. Configure the **OpenAI Chat Model** sub-node with the Xantly credential; agent runs route through Xantly too.

For tool-heavy agents (HTTP Request tools, Google Search tools), use `anthropic/claude-sonnet-4.6` as the agent's model, it's the most reliable tool-caller.

## RAG with Vector Store nodes

n8n ships Pinecone, Qdrant, Supabase Vector nodes. Pair them with:

- **OpenAI Embeddings** node → pick your Xantly credential + model `openai/text-embedding-3-small`.
- **OpenAI Chat Model** node for the retrieval step → `xantly/auto-quality`.

The full RAG pipeline runs through Xantly, embedding + query both benefit from semantic cache and smart routing.

## HTTP Request node (advanced)

If a specific node doesn't expose base URL config (rare but possible), hit Xantly directly via **HTTP Request**:

| Field | Value |
|---|---|
| Method | POST |
| URL | `https://api.xantly.com/v1/chat/completions` |
| Authentication | Header Auth |
| Header Name | `Authorization` |
| Header Value | `Bearer xantly_sk_...` |
| Body | JSON: `{ "model": "xantly/auto-quality", "messages": [...] }` |

## Model choice

| Model ID | When |
|---|---|
| `xantly/auto-quality` | AI Agent, reasoning nodes. |
| `xantly/auto-value` | High-volume workflow nodes (classifiers, summarizers). |
| `xantly/auto-speed` | Simple text transforms, triggered frequently. |
| `anthropic/claude-sonnet-4.6` | Tool-calling AI Agent. |
| `openai/text-embedding-3-small` | Vector Store embeddings. |

## Verify

1. Create a Manual Trigger → OpenAI Chat Model (Xantly credential, `xantly/auto-speed`).
2. Input: `"say pong"`.
3. Execute the workflow.
4. Check your Xantly dashboard, the call logs with cost + model.

## What you get

- **Workflow-scale cache savings.** n8n often runs the same workflow thousands of times on different triggers. Same-prompt-shape semantic matches → massive cache hit rate.
- **Waterfall fallback.** A provider outage mid-workflow doesn't kill the execution, Xantly silently retries.
- **Memory across runs.** Set `X-Xantly-Memory-Mode: recall` as a custom header via the HTTP Request node, or inside a credential's extra headers config.
- **Cost tracking per workflow.** Create a separate Xantly API key per workflow (`n8n-leadqualifier`, `n8n-supporttriage`) and see per-workflow spend in the Xantly dashboard.
- **Budget caps per workflow**: each key has its own daily USD budget.

## Gotchas

**`Base URL` field not always visible.** Some older n8n versions hide this field. Upgrade to 1.50.0+ where it's prominent in the OpenAI credential form.

**`/v1` suffix required.**

**LangChain-based AI Agent node.** It's built on LangChain.js, so the underlying LLM config matches [LangChain TS](/docs/use-with-langchain-typescript). Same constraints apply.

**Tool-call reliability.** If the AI Agent's tools fire then hang (no follow-up response), swap the model from generic to `anthropic/claude-sonnet-4.6`, stronger tool-calling.

**Self-hosted vs cloud.** Both work identically. Cloud n8n doesn't restrict custom base URLs.

## Next steps

- [Zapier (OpenAI connector)](/docs/use-with-zapier-openai), the other big no-code automation tool.
- [LangChain TypeScript](/docs/use-with-langchain-typescript), the engine behind n8n's AI Agent.
- [OpenAI SDK (TypeScript)](/docs/use-with-openai-sdk-typescript), if you build custom n8n nodes.
- [Cost-Optimized Routing](/docs/cost-optimized-routing), critical for automated workflows at scale.
