feat: Expose OpenRouter extra parameters#2236
feat: Expose OpenRouter extra parameters#2236voxathon wants to merge 10 commits intoHeyPuter:mainfrom
Conversation
Added openrouter_extras parameter to complete method for enhanced functionality.
Improved error detection for OpenRouter 4xx responses to prevent unnecessary fallback attempts
Extract detailed error message from OpenRouter's nested response structure
|
Not against this, but we cannot comply with ZDR policies as we do keep data about prompts and responses internally and for moderation purposes |
|
We could still allow ZDR as it relates to OpenRouter. i.e., the user is asking OpenRouter not to retain data. if that's the case, is this mergeable? |
|
I don't think so, I think there's some inherent dangers with how openrouter_extras is destructured directly into the OpenAI SDK params. I'm concerned it could interfere with usage billing which would be quite significant. I do like the concept but I don't like how it's implemented. There probably needs to be strict validation of every option and a whitelist probably needs to be built |
|
GitHub Mobile seems to be glitching out but check out line 98 in Openrouter provider in this PR |
That's fair enough.
Oh, right. Whoops. Let me get on that. |
removed unknown escape hatch from IOpenRouterExtras added explicit sampler parameters added reasoning.max_tokens for Anthropic
- replaced spread operator with explicit destructuring and filtering - added OpenRouterCreateParams to avoid `as any` cast - only pass defined fields to upstream API
|
Slightly unprofessional for me to comment on this but I am enjoying the whimsical commit names lol |
|
Hey is there any issues in continuing this PR? If its stale I can try and work on it myself @voxathon |
tl;dr: This adds a typed passthrough
openrouter_extrasto the AI chat completion service to allow for advanced use-cases involving ZDR (Zero Data Retention), OpenRouter's built-in web search plugin, and structured outputs. This also allows users to enable thinking for Anthropic's Claude or control the CoT budget for Google's Gemini.Before this change, the
OpenRouterProviderhad cherry-picked parameters, which prevented users from utilizing OpenRouter-specific features such as:response_format)provider.order,allow_fallbacks)reasoning)Main Changes
src/backend/src/services/ai/chat/providers/types.tsIOpenRouterExtrasinterface with autocomplete for common parameters and[key: string]: unknownescape hatch for forward compatibilitysrc/backend/src/services/ai/chat/providers/OpenRouterProvider/OpenRouterProvider.tsopenrouter_extrasinto upstream OpenAI SDK requestssrc/backend/src/services/ai/AIInterfaceService.jsopenrouter_extras: { type: 'json' }to theputer-chat-completioninterface definitionsrc/puter-js/src/modules/AI.js'openrouter_extras'toPARAMS_TO_PASSarraysrc/backend/src/services/ai/chat/AIChatService.tsmetadata.rawstructureUsage
Output:
{ "logprobs": null, "finish_reason": "stop", "native_finish_reason": "stop", "index": 0, "message": { "role": "assistant", "content": "{\n\"latest_ai_developments\": [\n{\n\"company\": \"Google\",\n\"model_name\": \"Gemini 3 Pro\",\n\"release_date\": \"2025-11-18\",\n\"key_features\": [\"State-of-the-art reasoning capabilities\", \"...\"],\n\"availability\": [\"Gemini app\", \"AI Mode in Search\", \"...\"],\n\"source\": \"https://blog.google/...\"\n},\n{\n\"company\": \"Google\",\n\"announcement\": \"Deep Research Agent & Interactions API\",\n\"release_date\": \"2025-12-11\",\n\"key_features\": [\"Reimagined Deep Research agent\", \"Interactions API\", \"...\"],\n\"source\": \"https://techcrunch.com/...\"\n},\n{\n\"company\": \"OpenAI\",\n\"model_name\": \"GPT-5.2\",\n\"release_date\": \"2025-12-11\",\n\"key_features\": [\"Best model for everyday professional use\", \"...\"],\n\"source\": \"https://www.theverge.com/...\"\n}\n],\n\"market_context\": { \"...\": \"...\" },\n\"trend_analysis\": { \"...\": \"...\" },\n\"benchmark_highlights\": { \"...\": \"...\" }\n}", "refusal": null, "reasoning": "...", "reasoning_details": [ { "format": null, "index": 0, "type": "reasoning.text", "text": "..." } ], "annotations": [ { "type": "url_citation", "url_citation": { "url": "https://techcrunch.com/2025/12/11/google-launched-its-deepest-ai-research-agent-yet-on-the-same-day-openai-dropped-gpt-5-2/", "start_index": 0, "end_index": 0, "title": "Google launched its deepest AI research agent yet — on the same day OpenAI dropped GPT-5.2", "content": "..." } }, { "type": "url_citation", "url_citation": { "url": "https://blog.google/intl/en-africa/company-news/outreach-and-initiatives/a-new-era-of-intelligence-with-gemini-3/", "start_index": 0, "end_index": 0, "title": "A new era of intelligence with Gemini 3", "content": "..." } }, { "type": "url_citation", "url_citation": { "url": "https://developers.googleblog.com/new-gemini-api-updates-for-gemini-3/", "start_index": 0, "end_index": 0, "title": "New Gemini API updates for Gemini 3", "content": "..." } }, { "type": "url_citation", "url_citation": { "url": "https://www.theverge.com/ai-artificial-intelligence/842529/openai-gpt-5-2-new-model-chatgpt", "start_index": 0, "end_index": 0, "title": "GPT-5.2 is OpenAI’s latest move in the agentic AI battle", "content": "..." } }, { "type": "url_citation", "url_citation": { "url": "https://blog.google/technology/developers/interactions-api/", "start_index": 0, "end_index": 0, "title": "Interactions API: A unified foundation for models and agents", "content": "..." } } ] }, "usage": { "prompt": 19182, "completion": 928, "input_cache_read": 3 }, "via_ai_chat_service": true }Notes
puter.jsSDK will need to be rebuilt for client-side usageThis was done in an effort to address ( #2228 ).