Frameworks
You can find a few examples of using OpenRouter with other frameworks in this Github repository. Here are some examples:
-
Using
npm i openai
: github.- Tip: You can also use Grit to automatically migrate your code. Simply run
npx @getgrit/launcher openrouter
.
- Tip: You can also use Grit to automatically migrate your code. Simply run
-
Using LangChain for Python: github
-
Using LangChain.js: github
const chat = new ChatOpenAI({
modelName: "anthropic/claude-instant-v1",
temperature: 0.8,
streaming: true,
openAIApiKey: $OPENROUTER_API_KEY,
}, {
basePath: $OPENROUTER_BASE_URL + "/api/v1",
baseOptions: {
headers: {
"HTTP-Referer": "https://yourapp.com/", // Optional, for including your app on openrouter.ai rankings.
"X-Title": "Langchain.js Testing", // Optional. Shows in rankings on openrouter.ai.
},
},
});
- Using the Vercel AI SDK:
const config = new Configuration({
basePath: $OPENROUTER_BASE_URL + "/api/v1",
apiKey: $OPENROUTER_API_KEY,
baseOptions: {
headers: {
"HTTP-Referer": "https://yourapp.com/", // Optional, for including your app on openrouter.ai rankings.
"X-Title": "Vercel Testing", // Optional. Shows in rankings on openrouter.ai.
}
}
})
const openrouter = new OpenAIApi(config)