n8n
Connect AICredits to n8n workflows. Use the OpenAI node with a custom base URL to access Claude, Gemini, GPT-4o, and 300+ models inside n8n automations.
Use this page with an AI assistant
Opens a new chat with this docs URL and the correct AICredits base URLs.
n8n is an open-source workflow automation platform. Because AICredits is OpenAI-compatible, you can use it inside any n8n node that accepts a custom base URL — including the OpenAI node, the AI Agent node, and the HTTP Request node. This gives your automations access to Claude, Gemini, DeepSeek, and 300+ models with a single INR-billed API key.
Overview
There are three ways to use AICredits in n8n:
| Method | When to use | Setup effort |
|---|---|---|
| OpenAI node (custom creds) | Chat, summarise, classify, generate text | Minimal — 2-minute setup |
| HTTP Request node | Full control over request body, image gen, credits check | Low |
| AI Agent node | Multi-step autonomous agents with tools | Medium |
OpenAI Node — Custom Credentials
The n8n OpenAI node supports a custom base URL via OpenAI API credentials. Set it once and every OpenAI node in your workspace automatically uses AICredits.
- Open Credentials → New → OpenAI API — Go to Settings → Credentials → Add Credential → OpenAI API.
- Set the API Key — Paste your AICredits API key (starts with
sk-) into the API Key field. - Set a custom Base URL — Expand Additional Fields and set Base URL to
https://api.aicredits.in/v1. - Save and use in any OpenAI node — Select these credentials in any OpenAI node. In the Model field, type the AICredits model ID directly, e.g.
anthropic/claude-sonnet-4.5.
Because AICredits supports model IDs from all providers, a single n8n credential lets you use GPT-4o in one node and Claude Sonnet in another — without managing separate API keys.
HTTP Request Node
Use the HTTP Request node for full control — useful for image generation, checking your credit balance, or passing custom parameters the OpenAI node does not expose.
Chat Completions:
Method: POST
URL: https://api.aicredits.in/v1/chat/completions
Headers:
Authorization: Bearer {{ $credentials.aicreditsApiKey }}
Content-Type: application/json
Body (JSON):
{
"model": "openai/gpt-4o-mini",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "{{ $json.user_message }}" }
],
"temperature": 0.7,
"max_tokens": 512
}Check Credit Balance:
Method: GET
URL: https://api.aicredits.in/v1/credits
Headers:
Authorization: Bearer {{ $credentials.aicreditsApiKey }}
# Response:
{
"balance_inr": 245.50,
"currency": "INR"
}Image Generation:
Method: POST
URL: https://api.aicredits.in/v1/images/generations
Headers:
Authorization: Bearer {{ $credentials.aicreditsApiKey }}
Content-Type: application/json
Body (JSON):
{
"model": "dall-e-3",
"prompt": "{{ $json.image_prompt }}",
"size": "1024x1024",
"quality": "standard",
"n": 1
}
# Access the URL in subsequent nodes via:
# {{ $json.data[0].url }}AI Agent Node
n8n's AI Agent node (under the LangChain section) supports a custom OpenAI-compatible chat model. This lets you build autonomous agents inside n8n that call tools like web search, database queries, or other n8n nodes.
- Add an AI Agent node — In your workflow, add the AI Agent node from the LangChain category.
- Add a Chat Model sub-node — Click + on the Chat Model input → select OpenAI Chat Model → choose your AICredits credential and set the model ID.
- Add tools — Connect tool nodes (Wikipedia, Calculator, HTTP Request, etc.) to the Tools input of the agent.
- Set the system prompt and input — Configure the agent's system prompt and pass the user's input message from a previous node.
The AI Agent node runs a full ReAct loop — the model reasons, picks a tool, observes the result, and repeats until it has a final answer. All intermediate LLM calls are billed to your AICredits wallet.
Example Workflows
Classify & Route Messages
Classify incoming Telegram/WhatsApp messages and route them to different downstream nodes:
# Workflow: Telegram Trigger → OpenAI Node → Switch Node
# OpenAI Node config:
Operation: Message a Model
Model: openai/gpt-4o-mini
System Prompt: |
Classify the user message into exactly one of these categories:
billing, technical, sales, general
Reply with only the category name — no other text.
User Message: {{ $json.message.text }}
# Switch Node routes on {{ $json.message.content }}:
- billing → Billing Support workflow
- technical → Tech Support workflow
- sales → Sales CRM workflow
- general → FAQ auto-replySummarise Emails
Trigger on new Gmail messages and generate a one-sentence summary to post in Slack:
# Workflow: Gmail Trigger → OpenAI Node → Slack Node
# OpenAI Node:
Operation: Message a Model
Model: anthropic/claude-haiku-4.5-20251001
System Prompt: Summarise the email in one sentence. Start with the sender's name.
User Message: |
From: {{ $json.from.value[0].address }}
Subject: {{ $json.subject }}
{{ $json.text }}
# Slack Node:
Channel: #email-digest
Message: 📧 {{ $node["OpenAI"].json.message.content }}Extract Structured Data
Extract structured fields from unstructured text (invoices, forms, tickets) and write to Google Sheets:
# Workflow: Webhook → OpenAI Node → Google Sheets Node
# OpenAI Node:
Operation: Message a Model
Model: openai/gpt-4o-mini
System Prompt: |
Extract the following fields from the text and respond with JSON only:
{
"vendor_name": string,
"invoice_number": string,
"amount": number,
"currency": string,
"due_date": "YYYY-MM-DD"
}
If a field is missing, use null.
User Message: {{ $json.invoice_text }}
# Parse the JSON in a Code node:
# const data = JSON.parse($input.first().json.message.content);
# return [{ json: data }];Tips
- Use expression mode for dynamic model selection — Set the Model field to an expression like
{{ $json.preferred_model || 'openai/gpt-4o-mini' }}to pick models dynamically per workflow run. - Add a low-balance check before expensive nodes — Use the HTTP Request node to GET
/v1/creditsand add an IF node — stop the workflow ifbalance_inr < 10to avoid failed requests. - Use JSON mode for extraction workflows — Enable Response Format: JSON to guarantee parseable output. Combine with a Code node to safely parse and pass fields downstream.
- Store the API key as an n8n credential — Never paste the API key directly into node parameters. Create an OpenAI API credential once and reference it via
{{ $credentials.aicreditsApiKey }}for secure, centralised key management. - Switch models mid-workflow for cost optimisation — Use
gpt-4o-minifor classification/extraction (cheap, fast) andclaude-sonnetonly for final response generation (quality). This reduces cost by 80–90% vs using a frontier model throughout.