You can use TanStack AI to integrate OpenRouter with your React, Solid, or Preact applications. The OpenRouter adapter provides access to 300+ AI models from various providers through a single unified API. To get started, install @tanstack/ai-openrouter:
You can configure the OpenRouter adapter with additional options:
OpenRouter provides access to 300+ models from various providers. Models use the format provider/model-name:
See the full list at openrouter.ai/models.
Set your API key in environment variables:
TanStack AI supports OpenRouter’s powerful routing features through the modelOptions parameter. You can configure model fallbacks, provider sorting, and data policies.
Specify backup models to try if the primary model is unavailable:
Sort providers by price, throughput, or latency instead of using the default load balancing:
Specify an explicit order of providers to try:
Control data collection and use Zero Data Retention (ZDR) providers:
Include or exclude specific providers:
Set maximum price limits for requests:
For more advanced routing options like performance thresholds and partition-based sorting, see the Provider Routing documentation.
For more information and detailed documentation, check out these resources: