The OpenRouter enables OutSystems applications to seamlessly integrate with OpenRouter’s unified API, providing access to a wide range of advanced AI models — including OpenAI, Anthropic, Google, Mistral, and more — via a single, simplified interface.
It abstracts the complexity of REST APIs, allowing developers to quickly implement features such as chatbots, summarization, text generation, and real-time AI messaging.
Download the OpenRouter from OutSystems Forge.
Add it as a dependency in your application:
In Service Studio, open Manage Dependencies.
Search for OpenRouter and include it in your module.
OpenRouter Account: Register here
API Key: Generate your API key from your OpenRouter dashboard
Model ID: Select an appropriate model from OpenRouter (e.g., mistralai/mixtral-8x7b, meta-llama/llama-3.1-405b-instruct, etc.)
In your logic flow, drag and drop the OpenRouter Connector Server Action wherever you want to make an OpenRouter API call.
Parameter
Type
Required
Description
api_key
Text
✔️
Your OpenRouter API key
model_id
The model you want to use (e.g., mistralai/mixtral-8x7b, meta-llama/llama-3.1-405b-instruct)
content_type
❌
Defaults to application/json if not specified
messages
List
List of message objects with role and content
💡 Example messages JSON:
[
{ "role": "system", "content": "You are a helpful assistant that provides clear and accurate answers to user questions." },
{ "role": "user", "content": "Who is the first Prime Minister of India?" }
]
🧠 Common roles: system, user, assistant.
The Server Action returns a result property containing the AI-generated response. You can parse and bind this result in your UI.
The OpenRouterConnector_Demo module (available on Forge) demonstrates a working use-case: summarizing long paragraphs using an AI model from OpenRouter.
API Key Configuration: Set your API key in the OpenRouter_ApiKey Site Property.
Model Id Configuration: Users can specify the model to be used via the Model Id input field (e.g., meta-llama/llama-3.1-405b-instruct).
Messages Structure:
System message: "You are a helpful assistant that summarizes long text into a short and clear paragraph."
User message: The paragraph inputted by the user.
The user enters a paragraph in the "Text to Summarize" input.
User provides a Model ID (e.g., meta-llama/llama-3.1-405b-instruct).
On clicking "Summarize", the connector is triggered and sends both messages to OpenRouter.
The summarized output is shown in the "Summary" field.
Model Id: Text input to specify the model to use for the request.
Text to Summarize: Large input field for entering the paragraph.
Summarize Button: Executes the API call.
Summary Output: Displays the AI-generated summary.
Download and publish OpenRouterConnector_Demo from Forge.
Set your API key in the OpenRouter_ApiKey Site Property.
{ "role": "system", "content": "You are a helpful assistant that summarizes long text into a short and clear paragraph." },
{ "role": "user", "content": "<User Input Paragraph>" }
api_key: GetSiteProperty("OpenRouter_ApiKey")
model_id: "meta-llama/llama-3.1-405b-instruct" (or user-selected)
messages: as above
// On Summarize Button Click
messages = [
{ role: "system", content: "You are a helpful assistant that summarizes long text into a short and clear paragraph." },
{ role: "user", content: InputParagraph }
response = OpenRouterConnector.ServerAction(
api_key = GetSiteProperty("OpenRouter_ApiKey"),
model_id = UserSelectedModelId,
messages = messages
)
SummarizedResult.Text = response.result
🔐 API Key Security: Store API keys in Site Properties or environment variables. Avoid hardcoding.
🗂️ Message Format: Use clear role and content structure for prompts.
⚠️ Error Handling: Handle timeouts, null responses, and invalid keys gracefully.
🤖 Model Selection: Choose appropriate models based on use-case. Refer to OpenRouter’s model catalog for full listings.
Issue
Solution
Invalid API Key [401]
Ensure the key is correct and active on OpenRouter.
No Response/Timeout
Check internet connectivity and model availability.Increase Server Request Timeout ( in secs)
Unexpected Output
Tweak the system prompt or try a different model_id.