Agent Component with OpenRouter
Goal: Add Agent Component to my web and React Native app with Expo
Subgoal: I want the user to be able to switch models easily (hence OpenRouter)
I had this working with Convex without the Agent Component, but I wanted to switch to using the Agent Component.
1. Is there no need for an API key, even for OpenAI integration? I do not see in the docs or video tutorials (like here https://www.youtube.com/watch?v=tUKMPUlOCHY&t=308s) where an API key is used. I imagine it is in an environment variable, but I just did not see it in the docs or video.
2. Is OpenRouter not supported? It looks like the Agent Component expects LanguageModelV1 for
chat
and createOpenRouter({apiKey: ...})
gives a type of OpenRouterChatLanguageModel which is apparently v2.
Here is the current code in my convex directory and the error on chat
process.env.OPENROUTER_BASE_URL
is https://openrouter.ai/api/v1
Below is the actual type error
Convex
YouTube
Powerful AI Apps Made Easy with the Agent Component
If you’re a developer looking to build full-stack AI apps without dealing with messy orchestration, this video is your shortcut. Learn how to integrate the open-source Agent Component from Convex into your project to build real-time, intelligent chat interfaces powered by LLMs like GPT-4.1 mini. All in TypeScript.
Resources
- Agent component ...
11 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
you just call openrouter(model) and make sure the api key is set on convex. its actually quite simple
That is amazing. Going to go try it now. I will take that simplicity even if it means I spent 2 hours unnecessarily debugging.
Is there any expectation of what the key should be called on convex?
OPENROUTER_API_KEY is what I suspect
yep
https://discordapp.com/channels/1019350475847499849/1384983022729826376 i was inspired by the getModel setup here and made like a slight modification for my agent init
Where do you import openrouter from to call openrouter(model)?
import { openrouter } from '@openrouter/ai-sdk-provider'
you might need to call openrouter.chat( depending
Okay, then based on what you were saying, I was doing it the right way all along. When I do that I get the error
When I dug into it, I think OpenRouter is structuring it with v2 of LanguageModels but the Convex Agent Component expects v1.

I get the same error with or without .chat(
@ampp do you prefer I ping you if I ask something new?
I did confirm that the Convex examples show that it should just work like you said, ampp.
I have reached out to the OpenRouter team. I am also going to check what version of the
@openrouter/ai-sdk-provider
is in the example repo. I may just install that version.
Just to document it, I can confirm the Agent Component works with @openrouter/ai-sdk-provider@0.7.1
. I will update if the OpenRouter team updates me with the latest version that still uses v1.
Also, would the Convex team be open to help in upgrading the Agent Component to v2? I am open to working on it, but I wanted to avoid assuming the help was wanted. If it is wanted, please let me know anything you would like me to be mindful of other than what is in the CONTRIBUTING.md.there is the #agents chat here if you aren't aware
Thank you! No I was not aware