From cb3aa48999627cfa52c627be7cde6210409d5846 Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 12 Apr 2026 13:37:31 +0200 Subject: [PATCH] fix: Add wrapper function for workflow LLM calls to prevent max_tokens signature mismatch Problem: workflow_executor calls openrouter_call_func(prompt, model) but call_openrouter expects (prompt, max_tokens=4096). This caused the model string 'anthropic/claude-sonnet-4' to be passed as max_tokens, resulting in OpenRouter requesting 64000 tokens and failing with 402 credit errors. Solution: Added workflow_llm_call() wrapper in workflows.py that matches the expected (prompt, model) -> str signature and calls call_openrouter correctly. Fixes: All workflows failing with 402 'insufficient credits' errors --- backend/routers/workflows.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/routers/workflows.py b/backend/routers/workflows.py index d37f5b2..b13d52e 100644 --- a/backend/routers/workflows.py +++ b/backend/routers/workflows.py @@ -86,11 +86,19 @@ async def execute_workflow_endpoint( "type": "workflow" } + # Wrapper function to match workflow_executor's expected signature: (prompt, model) -> str + # workflow_executor calls: openrouter_call_func(prompt, "anthropic/claude-sonnet-4") + # but call_openrouter expects: call_openrouter(prompt, max_tokens=4096) + async def workflow_llm_call(prompt: str, model: str) -> str: + # Ignore model parameter (already set in OPENROUTER_MODEL env var) + # Use default max_tokens=4096 from call_openrouter + return await call_openrouter(prompt) + try: result = await execute_workflow_prompt( prompt=workflow_prompt, variables=variables, - openrouter_call_func=call_openrouter, + openrouter_call_func=workflow_llm_call, # Use wrapper with correct signature enable_debug=request.enable_debug ) return result