# Use GPT and Claude in n8n with one API key

> Route GPT and Claude in n8n through a single OpenAI-compatible base URL and API key, keeping one balance and switching models per node.

**You can run both GPT and Claude in n8n with one API key by pointing n8n's OpenAI connection to the thelastapi gateway.** The gateway exposes an OpenAI-compatible endpoint at `https://thelastapi.dev/v1/ai`, allowing you to route requests to GPT-6 Luna, Claude Sonnet 5.5, or any specific lab model ID through a single credential. You maintain one prepaid balance, set unified spending caps, and swap models between workflow steps by changing only the model name.

Using multiple model providers in automation tools often leads to maintenance headaches. This guide shows how the gateway works, how to configure n8n, and how to control your usage.

## Why run both models through one endpoint

Workflows in n8n often need different models for different steps. You might want a fast, low-cost model to classify incoming webhooks, extract JSON fields, or filter out spam. A few steps later, you might need a model with strong reasoning or nuanced writing to draft customer responses or write code.

Setting this up directly with each lab introduces operational friction:

- **Separate API keys and accounts.** You must generate, store, and rotate keys across multiple dashboards.
- **Fragmented balances.** You have to pre-fund credits or maintain separate payment cards for each vendor. If one runs out of credits, a branch of your automation silently stops.
- **Incompatible request nodes.** In n8n, shifting a prompt from GPT to Claude normally requires rebuilding the node logic or swapping node types.

Because the thelastapi gateway uses the OpenAI chat completions format, n8n treats both GPT and Claude as standard OpenAI calls. To understand the architectural design behind this, see [how a unified AI API works](https://thelastapi.dev/blog/one-api-key-gpt-claude-gemini).

## How the gateway handles GPT and Claude

When your n8n workflow sends a request to `https://thelastapi.dev/v1/ai/chat/completions`, the gateway inspects the `model` field. You can request a model using a standard role alias or a direct model identifier from the lab:

- **Role-based models**: These provide stable names mapped to specific lab models. For instance, `vibiz/fast` runs OpenAI's GPT-6 Luna, while `vibiz/smart` runs Anthropic's Claude Sonnet 5.5.
- **Lab model IDs**: You can call any model directly by its lab name, such as `anthropic/claude-opus-5.5`.

The gateway never performs silent fallbacks. If you ask for `vibiz/smart` and the model cannot be reached, the call returns an error (`503 model_unavailable` or `503 provider_unavailable`). It will never quietly route your prompt to a different model. Every response includes `served_model` showing what ran and `cost_micro_usd` showing the exact cost of the generation.

Here is how key models compare on the gateway:

| thelastapi model | Runs on | Best suited for | Price per million tokens (in / out) |
| --- | --- | --- | --- |
| `vibiz/fast` | GPT-6 Luna (OpenAI) | Fast JSON extraction, triage, tool calls | $0.10 / $0.50 |
| `vibiz/smart-mini` | Claude Haiku 5.5 (Anthropic) | Quick customer responses, fast summaries | $0.10 / $0.50 |
| `vibiz/reasoning` | GPT-6.1 Terra (OpenAI) | Math, complex logic, step-by-step planning | $1.00 / $5.00 |
| `vibiz/smart` | Claude Sonnet 5.5 (Anthropic) | Long writing, complex code, multi-step analysis | $2.00 / $10.00 |
| `vibiz/pro` | Claude Opus 5.5 (Anthropic) | Highest-complexity reasoning tasks | $4.00 / $20.00 |

Over 400 language models can be queried this way. You can review the complete catalogue in the [AI docs](https://thelastapi.dev/docs/ai).

## Step 1: Get your API key

You can access the gateway with either an account key or a project-specific AI key. New accounts start with $2.00 of trial credit, as outlined in the [billing and credits guide](https://thelastapi.dev/docs/billing).

To create a dedicated key from your terminal, install the CLI and generate an API key:

```bash
vibiz keys create n8n-automation
```

The CLI outputs a key starting with `vz_sk_`. Store this secret securely.

If you are organizing your work under a specific project, you can generate a project AI key instead:

```bash
vibiz init "Automation Ops" --resources ai
vibiz dev
```

This writes your project configuration and credentials, including `VIBIZ_AI_API_KEY` (which starts with `vz_ai_`) and `VIBIZ_AI_BASE_URL`, to `.env.development.local`. More key management options are detailed in [keys and environments](https://thelastapi.dev/docs/keys).

## Step 2: Configure n8n credentials

In n8n, you can connect to the gateway using the built-in OpenAI Chat Model node or an HTTP Request node.

### Option A: Using the OpenAI Chat Model node

1. In n8n, create or open your workflow.
2. Add an **OpenAI Chat Model** node (or an **AI Agent** node connected to an OpenAI Chat Model).
3. Under **Credential to connect with**, select **Create New Credential**.
4. Set **API Key** to your thelastapi key (`vz_sk_...` or `vz_ai_...`).
5. Open the credential's advanced settings and set **Base URL** to:
   ```text
   https://thelastapi.dev/v1/ai
   ```
6. Save the credential.

Once saved, this single credential can invoke both OpenAI and Anthropic models across your workflow.

### Option B: Using an HTTP Request node

If you prefer direct HTTP calls without using n8n's native AI nodes, you can use an HTTP Request node configured as follows:

- **Method**: `POST`
- **URL**: `https://thelastapi.dev/v1/ai/chat/completions`
- **Authentication**: Generic Credential Type -> Header Auth (or set a raw header)
- **Header**: `Authorization: Bearer vz_sk_...`
- **Header**: `Content-Type: application/json`

The raw request body follows the OpenAI specification:

```json
{
  "model": "vibiz/fast",
  "messages": [
    {
      "role": "system",
      "content": "Extract the customer sentiment and priority level as JSON."
    },
    {
      "role": "user",
      "content": "Our production sync stopped working twenty minutes ago!"
    }
  ],
  "response_format": { "type": "json_object" }
}
```

If you are calling models from custom scripts alongside n8n, check out [how to use Claude with the OpenAI Python SDK](https://thelastapi.dev/blog/claude-with-openai-python-sdk) and [function calling across GPT, Claude and Gemini with one API](https://thelastapi.dev/blog/function-calling-multiple-models).

## Step 3: Route between GPT and Claude in a single workflow

Once your credential is in place, you can alternate between providers simply by setting the `model` parameter inside each node.

Consider a multi-stage customer support pipeline:

1. **Intake and Classification Node (OpenAI)**:
   - Node: OpenAI Chat Model
   - Credential: thelastapi connection
   - Model name: `vibiz/fast`
   - Purpose: Classify the ticket into billing, technical, or account issues. Because GPT-6 Luna runs at $0.10 per million input tokens, high-volume classification remains inexpensive.

2. **Conditional Logic (Switch Node)**:
   - Directs the ticket based on the classification output.

3. **Complex Resolution Drafting (Claude)**:
   - Node: OpenAI Chat Model
   - Credential: Same thelastapi connection
   - Model name: `vibiz/smart` (or `anthropic/claude-opus-5.5`)
   - Purpose: Review historical logs and draft a technical response. Claude Sonnet 5.5 handles the context and produces a detailed technical reply.

To verify a call from your terminal before deploying your n8n workflow, use `curl`:

```bash
curl https://thelastapi.dev/v1/ai/chat/completions \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "vibiz/smart",
    "messages": [
      {"role": "user", "content": "Explain idempotency keys in payment APIs."}
    ]
  }'
```

## Monitor usage and control spending

Automations that run on timers or inbound webhooks can encounter recursion bugs or traffic spikes. The gateway includes controls to prevent unexpected costs.

### Default safety limits

- **Account daily limit**: By default, an account is capped at $5.00 per UTC day across AI calls and actions. You can raise this limit in the console under Billing or using the CLI:
  ```bash
  vibiz billing limit 25
  ```
- **Project budget**: Projects have a default daily AI limit of $1.00. You can adjust this with:
  ```bash
  vibiz ai budget 10 --project prj_123
  ```
- **Rate limits**: An account key supports 300 requests and 400,000 tokens per minute (with 50 concurrent requests in flight). A project key supports 120 requests and 200,000 tokens per minute.

When a limit is reached, the API returns an HTTP `429 rate_limited` error with a JSON body indicating the reason, such as `daily_spend` or `project_budget`. Owners receive automated warning emails at 80% and 100% of any daily cap. See [usage and limits](https://thelastapi.dev/docs/usage) for complete details.

### Inspecting workflow spend

Every completed chat response carries metadata showing the charge:

```json
{
  "id": "chatcmpl_123",
  "object": "chat.completion",
  "served_model": "anthropic/claude-sonnet-5.5",
  "cost_micro_usd": 1240,
  "choices": [...]
}
```

You can view aggregated spending by model directly from the command line:

```bash
vibiz usage --by model --period 24h
```

If you manage public applications alongside your internal automations, you can also [deploy a website from Claude or ChatGPT with nothing installed](https://thelastapi.dev/blog/deploy-website-from-claude-chatgpt) and manage both backends from the same dashboard.

To get started, set up your n8n OpenAI credential with `https://thelastapi.dev/v1/ai` as the base URL, enter your API key, and begin calling both GPT and Claude across your workflows.

## Frequently asked questions

### Can I use tool calling and structured JSON mode with Claude through this endpoint?

Yes. The gateway translates OpenAI-style tool definitions and JSON mode specifications across models, including Claude, so you can run function calling reliably in n8n.

### What happens if an automation triggers a rate limit or runs out of credits?

If you exceed a daily spending limit, the endpoint returns an HTTP 429 error with the specific cap named in `details.reason`. If your prepaid credits drop to zero or below, requests return an HTTP 402 `payment_required` error.

### Does n8n require different base URLs for GPT and Claude when using this setup?

No. Both models run through the exact same base URL (`https://thelastapi.dev/v1/ai`) and API key, and n8n routes between them purely based on the model ID you provide in each node.

### What is the maximum output length per request?

The default `max_tokens` value is 1,024 when omitted, and you can specify up to 16,384 tokens depending on the chosen model's supported limit.

---

Published 2026-11-15 · https://thelastapi.dev/blog/n8n-gpt-claude-one-key
