openrouter-examples icon indicating copy to clipboard operation
openrouter-examples copied to clipboard

Examples of integrating the OpenRouter API

OpenRouter Examples

Use the examples folder in this repo to integrate different SDKs with OpenRouter.

OpenRouter is an API that can be used with most AI SDKs, and has a very similar format to OpenAI's own API.

Below, you can find different SDKs adapted to use OpenRouter.

npm openai

Use this example to run the npm openai package using OpenRouter.

LangChain.js

Use this example to run LangChain.js scripts using OpenRouter.

Changing models

Change the model you want to use by configuring modelName in index.ts. You can use models from OpenAI, Anthropic, Google, and more. See the OpenRouter docs for all the options.

OAuth

You can let users use OpenRouter OAuth to authenticate and pay for models instead of using your own key. This example doesn't include that code yet (PRs welcome), but you can find an example in Python + Streamlit here.