OpenRouter Integration with SmythOS
Want to use any AI model without juggling multiple APIs? Connect OpenRouter to SmythOS and give your agents access to hundreds of LLMs through a single, powerful component.
List of OpenRouter Components
The OpenRouter integration provides a single, flexible component that can be used to access any supported model.
Component | Action | What it Does | Inputs | Key Outputs | Use Case |
---|---|---|---|---|---|
Chat Completion | AI Task | Runs text generation or chat on hundreds of different LLMs. | required prompt optional model | message_content | Any NLP task: summarization, writing, Q&A, etc. |
Prerequisites
Before you begin, please ensure you have the following:
- An active SmythOS account. (Sign up here).
- An OpenRouter account.
- Your OpenRouter API Key.
Getting Started With OpenRouter
The connection between SmythOS and OpenRouter is configured using a secure API key.
Step 1: Get Your OpenRouter API Key
- Log in to your OpenRouter account.
- Navigate to the Keys section of your account settings.
- Click Create Key, give it a name, and copy the generated key.
Step 2: Store Your API Key in SmythOS Vault
Your API Key is a sensitive credential. Use the SmythOS Vault
to store it securely.
- In your SmythOS dashboard, navigate to the Vault.
- Create a new secret and paste your OpenRouter API Key as the value. Give it a memorable name, like
openrouter_api_key
. - For more details, see the Vault Documentation.
Step 3: Configure the OpenRouter Component
- In your SmythOS agent graph, drag and drop the OpenRouter Chat Completion component.
- Click the component to open its Settings panel.
- In the
API Key
field, select the secret you saved in the Vault (e.g.,openrouter_api_key
). - Your connection is now configured for that component.
Which OpenRouter Model Should I Use?
If you need to… | Task Type | Recommended Model (Example) | Why this one? |
---|---|---|---|
Write a high-quality blog post | Creative Writing | openai/gpt-4-turbo or anthropic/claude-3-opus | State-of-the-art models with strong reasoning and writing skills. |
Quickly classify an email | Simple Classification | mistralai/mistral-7b-instruct | A fast and highly capable open-source model that is very cost-effective. |
Summarize a technical document | Summarization | google/gemini-pro | Strong at understanding and condensing complex information. |
Let the system choose the best model | Automatic | openrouter/auto | OpenRouter will route your request to the best model based on price and performance. |
Component Details
This section provides detailed information for the OpenRouter component.
Chat Completion
Provides a unified interface to send prompts to hundreds of different Large Language Models (LLMs).
Inputs
Field | Type | Required | Notes |
---|---|---|---|
prompt | string | Yes | The text input or question to send to the language model. |
model | string | Optional | The ID of the model you want to use (e.g., openai/gpt-3.5-turbo ). Defaults to openrouter/auto . |
Outputs
Field | Type | Description |
---|---|---|
message_content | string | The text content of the AI's generated response. |
id | string | The unique identifier for the completion request. |
Response | object | The full, raw JSON response from the OpenRouter API, including usage data. |
Headers | object | The HTTP headers from the API response. |
{
"component": "openrouter.chatCompletion",
"prompt": "Explain the concept of zero-shot learning in 50 words or less.",
"model": "anthropic/claude-3-sonnet"
}
Best Practices & Advanced Tips
- Secure Your API Key: Always use the SmythOS
Vault
to store your OpenRouter API key. - Model Selection is Key: The most important choice you'll make is the
model
. For simple, repetitive tasks, choose a fast, cheap model. For complex, creative, or multi-step reasoning, choose a state-of-the-art model. - Leverage
openrouter/auto
: If you're unsure which model to use, theauto
setting is a great starting point. OpenRouter will choose a suitable model for you. - Prompt Engineering: The quality of your output depends heavily on the quality of your
prompt
. Be clear, specific, and provide context or examples for the best results.
Troubleshooting Common Issues
-
Error:
401 Unauthorized
- Cause: The API key is missing, invalid, or disabled.
- Solution: Verify that the API key in your SmythOS Vault is correct and matches the one in your OpenRouter dashboard.
-
Error:
402 Payment Required
- Cause: You have insufficient credits in your OpenRouter account.
- Solution: Log in to your OpenRouter account and add credits to your balance.
-
Error:
404 Not Found
(for a model)- Cause: The
model
ID you provided is incorrect, misspelled, or not supported by OpenRouter. - Solution: Check the OpenRouter Models page for the correct, full model ID string (e.g.,
openai/gpt-4-turbo
).
- Cause: The
-
Error:
429 Too Many Requests
- Cause: You have exceeded the rate limit for a specific model or for your account in general.
- Solution: Add a delay in your agent between frequent calls. Some models have stricter rate limits than others.
What's Next?
You are now ready to build incredibly flexible AI agents with the SmythOS OpenRouter Integration!
Consider these ideas:
-
Build an Agent That...
- Acts as a "writer's assistant." It first generates a blog post outline using a fast model like Mistral, then takes the approved outline and writes the full article using a powerful model like Claude 3 Opus.
- Analyzes customer feedback. It uses a cheap model to quickly classify feedback as positive or negative. For negative feedback, it uses a more powerful model to draft a thoughtful, empathetic response.
- A/B tests different AI models for a specific task. Send the same prompt to two different models via OpenRouter and compare their outputs to see which performs better for your use case.
-
Explore Other Integrations:
- Combine OpenRouter with the ScrapingBee Integration to scrape content from a website and then use any LLM to summarize or analyze it.
- Generate text with an OpenRouter model and then give it a voice using the Elevenlabs Integration.
- Use OpenRouter to process data before logging it to a Google Sheet or sending it as an Gmail.