Describe the problem/error/question
I created an AI agent with openrouter. It works when in test mode flawlessly. but when I make the workflow active, and run it with a cron trigger, the api key fails. Anyone know the reason for this?
What is the error message (if any)?
Authorization failed - please check your credentials
Incorrect API key provided: sk-or-v1*************************************************************fe11. You can find your API key at https://platform.openai.com/account/api-keys.
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
{
"nodes": [
{
"parameters": {
"databaseId": 1,
"tableId": 3,
"returnAll": true,
"additionalOptions": {}
},
"type": "n8n-nodes-base.baserow",
"typeVersion": 1,
"position": [
-140,
-80
],
"id": "a58c6468-9f43-487b-8903-aa93b7c3579a",
"name": "Baserow",
"credentials": {
"baserowApi": {
"id": "b7Y4I4TJZb33ejAF",
"name": "Baserow account - contentsprout"
}
}
},
{
"parameters": {
"model": {
"__rl": true,
"value": "deepseek/deepseek-r1-distill-qwen-14b",
"mode": "list",
"cachedResultName": "deepseek/deepseek-r1-distill-qwen-14b"
},
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.2,
"position": [
60,
220
],
"id": "e833dd3e-641d-402f-9685-36edca838805",
"name": "OpenAI Chat Model",
"credentials": {
"openAiApi": {
"id": "lj7opvoCxbMSqKLn",
"name": "openrouter - hacheng1"
}
}
},
{
"parameters": {
"operation": "update",
"databaseId": 1,
"tableId": 3,
"rowId": "={{ $('Baserow').item.json.id }}",
"fieldsUi": {
"fieldValues": [
{
"fieldId": 32,
"fieldValue": "={{ $json.score }}"
}
]
}
},
"type": "n8n-nodes-base.baserow",
"typeVersion": 1,
"position": [
1240,
-60
],
"id": "ad7ef737-8d71-4fed-928a-225f6c602009",
"name": "Baserow1",
"credentials": {
"baserowApi": {
"id": "b7Y4I4TJZb33ejAF",
"name": "Baserow account - contentsprout"
}
}
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "1c73adc0-b753-4f29-9113-9021647392a2",
"name": "score",
"value": "={{ $json.score }}",
"type": "number"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1020,
-100
],
"id": "1e39b435-3f6c-4257-88da-454b598caedd",
"name": "Edit Fields"
},
{
"parameters": {
"promptType": "define",
"text": "=You are an expert lead scorer for an AI development and automation agency. \nWe focus on companies making over $1M annually that might hire us for AI or automation solutions.\n\nAnalyze the following LinkedIn headline and assign it a lead score according to these rules:\n\nScoring Guidelines (0–10):\n\n0: Not Relevant\n- Student, intern, or trainee roles\n- Competitor companies (AI/automation agencies)\n- Clearly not an industry fit or no capacity for AI/automation investment\n\n1–3: Low Priority\n- Entry-level / individual contributor\n- Company size or role suggests < $1M revenue\n- No mention of technology, growth, or budget authority\n\n4–5: Medium Priority\n- Mid-level managers in potentially $1M+ companies\n- Some interest in efficiency or analytics\n- Not clearly a decision-maker but in a relevant industry\n\n6–7: High Priority\n- Senior leaders (Director, VP) in $1M+ revenue firms\n- Likely to adopt modern tech or shows partial AI/automation interest\n- Some budget or decision-making ability implied\n\n8–10: Perfect Leads\n- C-level, Founder, Board Member at $1M+ revenue companies\n- Clear references to AI, automation, or major digital transformations\n- Strong authority over budget and company direction\n\nOutput Requirements:\n1. Output exactly one JSON object with a single key: `score`.\n2. The value must be a float between 0 and 10, with no more than two decimal places (e.g., 8.50).\n3. Do not output arrays, code fences, extra text, or additional keys.\n4. No explanations or disclaimers—only the JSON object.\n\n**Example** of correct output:\n\n{\n“score”: 7.50\n}\n\nLinkedIn Headline to Score: {{ $json.headline }}",
"hasOutputParser": true,
"options": {
"systemMessage": "You are an AI that **must** respond with exactly one JSON object.\nThis JSON object has exactly one key: \"score\".\nThe value must be a float between 0 and 10 with at most two decimals.\nDo not output anything else—no code fences, no arrays, no explanations.\n\nExample of the only acceptable output:\n{\n \"score\": 7.50\n}"
}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 1.7,
"position": [
120,
-140
],
"id": "af518d1a-8336-4e44-bd9b-634c00db0d9a",
"name": "AI Agent1"
},
{
"parameters": {
"jsCode": "/**\n * This Code node will:\n * 1) Remove triple-backticks or other extraneous text around the JSON.\n * 2) Extract the JSON object from the string.\n * 3) Return items with the parsed \"score\".\n */\nreturn items.map(item => {\n // 1) Retrieve the string from item.json.output\n let rawOutput = item.json.output;\n\n // 2) Remove any ```json fences or triple backticks\n // (this also covers cases like ```json\\n{...}\\n```)\n rawOutput = rawOutput\n .replace(/```json/g, '')\n .replace(/```/g, '');\n\n // 3) Match the JSON portion between the first '{' and the final '}'\n // This allows ignoring any text before/after the JSON block.\n const jsonMatch = rawOutput.match(/\\{[\\s\\S]*\\}/);\n\n // 4) If there's no valid JSON block, default to a score of 0 (or handle how you prefer)\n if (!jsonMatch) {\n return {\n json: {\n score: 0\n }\n };\n }\n\n // 5) Parse the JSON substring\n const parsed = JSON.parse(jsonMatch[0]);\n\n // 6) Return each item with just the \"score\" in the final JSON\n return {\n json: {\n score: parsed.score\n }\n };\n});"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
-160
],
"id": "c65a115b-928f-4e39-ba88-d4b2c4b08886",
"name": "Code"
},
{
"parameters": {
"rule": {
"interval": [
{}
]
}
},
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [
-400,
-80
],
"id": "ff83f1e8-fe02-4a6a-8805-ff3f8929d279",
"name": "Schedule Trigger"
}
],
"connections": {
"Baserow": {
"main": [
[
{
"node": "AI Agent1",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent1",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "Baserow1",
"type": "main",
"index": 0
}
]
]
},
"AI Agent1": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Baserow",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "f91b0b942f68abc36946915b0c9cffe661493bd31ec6576b820cb389080a2205"
}
}
Share the output returned by the last node
Information on your n8n setup
- n8n version: 1.76.1
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app): self hosted on raiilway
- Operating system: mac os