PI OpenRouter Pro v4
Call the OpenRouter Chat Completions API with multimodal prompts, structured outputs, and usage tracking.
Overview
This node integrates with the OpenRouter Chat Completions API to generate chat-based completions using multimodal prompts, structured outputs, and usage tracking. It supports various input message types including text, images (binary or URL), audio, and video, allowing users to create complex chat interactions. The node is useful for scenarios such as AI chatbots, virtual assistants, and interactive applications that require dynamic and context-aware responses from advanced language models.
Use Case Examples
- Generating AI responses based on user input from a connected Chat Trigger node.
- Using custom system and user prompts to guide the chat model's behavior.
- Processing image inputs either from binary data or URLs to include in chat completions.
- Tracking usage and cost metadata for API calls to monitor consumption.
Properties
| Name | Meaning |
|---|---|
| Source for Prompt (User Message) | Determines the source of the user prompt, either from a connected Chat Trigger node, a connected Guardrails node, or a manually defined prompt. |
| Prompt (User Message) | The actual user message text to send to the chat model, sourced based on the selected prompt type. |
| Model Name or ID | Selects the language model to use for generating chat completions, either from a dropdown list or by specifying an ID via expression. |
| Temperature | Controls the randomness of the output; higher values produce more random results. |
| Max Output Tokens | Specifies the maximum number of tokens to generate in the response. |
| Advanced Parameters | Collection of optional advanced settings such as caching behavior, frequency and presence penalties, seed for deterministic sampling, stop sequences, and token sampling controls (topK, topP). |
| Enable Usage Tracking | Enables returning usage and cost metadata in the API response. |
| Prompt Templates | Optional system and user prompt templates that can be used to predefine messages sent to the model. |
| Messages | Additional messages to include in the chat, supporting text, images (binary or URL), audio, and video inputs with roles such as user, system, or assistant. |
| Enable Structured Output | Toggle to define response format requirements directly on the node. |
| Response Format Type | Specifies the type of structured output: plain text, JSON object, or JSON schema. |
| JSON Schema | Defines the JSON schema for structured output when JSON Schema format is selected. |
| JSON Schema Name | Name of the JSON schema for structured output. |
| JSON Schema Description | Description of the JSON schema for structured output. |
| Usage & Cost Tracking | Options to customize usage tracking details such as which token counts to include and whether to return cost breakdowns. |
| Output Mode | Determines the format of the node's output, including full API response, first completion text, structured JSON message, or usage summary. |
| Advanced Options | Additional advanced settings including logit bias, metadata, parallel tool calls, reasoning effort, response modifiers, streaming responses, tool choice, and tools JSON configuration. |
Output
JSON
text- Text of the first completion choice when output mode is 'First Completion Text'.content- Content of the first completion message, possibly structured JSON when output mode is 'Structured JSON Message'.usage- Usage and cost metadata when output mode is 'Usage Summary'.raw- Full API response JSON when output mode is 'Full Response'.
Dependencies
- OpenRouter API
- An API key credential for authentication
Troubleshooting
- Ensure a valid model is selected; errors occur if the model parameter is empty or invalid.
- Prompt text must not be empty; provide at least one system, user, or custom message before sending the request.
- Binary properties referenced in messages must exist in the input item; otherwise, an error is thrown.
- Streaming output mode requires 'Full Response' output mode; other output modes will cause errors if streaming is enabled.
- JSON schema for structured output must be valid JSON and an object; parsing errors will be reported.
Links
- n8n Expressions Documentation - Documentation on how to use expressions in n8n node parameters.
- OpenRouter API Documentation - Official API documentation for OpenRouter chat completions.