Skip to main content

OpenRouter

OpenRouter is a unified API gateway that facilitates AI model integration, offering access to multiple AI models through a single interface. OpenRouter provides chat completions, model listings, and text embeddings support, enabling developers to easily switch between different AI models and providers without changing their integration code. The OpenRouter API enables programmatic access to various AI models for natural language processing, text generation, and embeddings.

OpenRouter icon

Power end-to-end data operations for your OpenRouter API with Nexla. Our bi-directional OpenRouter connector is purpose-built for OpenRouter, making it simple to ingest data, sync it across systems, and deliver it anywhere — all with no coding required. Nexla turns API-sourced data into ready-to-use, reusable data products and makes it easy to send data to OpenRouter or any other destination. With comprehensive monitoring, lineage tracking, and access controls, Nexla keeps your OpenRouter workflows fast, secure, and fully governed.

Features

Type: API

SourceDestination

  • Seamless API Integration: Connect to any endpoint as source or destination without coding, with automatic data product creation
  • Visual Composition & Chaining: Build complex integrations using visual templates, chain API calls, and compose workflows with data validation and filtering
  • API Proxy: Expose curated slices of your data securely with a secure and customizable API proxy that validates and transforms data on the fly
  • Request optimization with intelligent batching, retry, and caching to minimize API calls and costs

Prerequisites

Before creating an OpenRouter credential, you'll need to obtain an API key from your OpenRouter account. OpenRouter uses API key-based authentication for API access.

To obtain the required API key for OpenRouter API access:

  1. Sign up for OpenRouter: Create an account at https://openrouter.ai if you don't already have one.

  2. Navigate to API Keys:

    • Log in to your OpenRouter account
    • Go to Settings > API Keys or Account > API Keys
    • Locate the API keys section
  3. Generate API Key:

    • Click Create API Key or Generate New Key to create a new API key
    • You'll receive an encoded string value that serves as your secret token
    • Copy the API key value immediately, as it may only be displayed once

OpenRouter API keys are specific to your account and should be kept secure. The API key is used to authenticate all API requests to OpenRouter. For detailed information about OpenRouter API authentication and API keys, refer to the OpenRouter API Documentation.

OpenRouter API access requires an active OpenRouter account, an API key generated from your OpenRouter account, and network access to https://openrouter.ai. For complete information about OpenRouter API setup and authentication, see the OpenRouter API Documentation.

Authenticate

Credentials required

An authentication method that requires sending a unique secret token with each API request on OpenRouter

FieldRequiredSecretDescription
API Key ValueYesYesAn encoded string value used as a secret token to authenticate API requests on OpenRouter

Create a credential in Nexla

  1. After selecting the data source/destination type, click the Add Credential tile to open the Add New Credential overlay.

New Credential Overlay – OpenRouter

OpenRouterCred.png
  1. Enter a name for the credential in the Credential Name field and a short, meaningful description in the Credential Description field.

  2. Enter your OpenRouter API key in the API Key Value field. This is the encoded string value that serves as a secret token to authenticate API requests on OpenRouter.

    The API key is sensitive information that should be kept secure. Nexla will store this credential securely and use it only for API authentication purposes. The API key is sent in the request headers with each API request to OpenRouter.

    OpenRouter API uses API key authentication, which is automatically handled by Nexla: the API key is included in request headers, all API requests use JSON content type, and the base URL is https://openrouter.ai/api/v1. You only need to provide your API key value.

  3. Click the Save button at the bottom of the overlay. The newly added credential will now appear in a tile on the Authenticate screen during data source/destination creation.

Use as a data source

To create a new data flow, navigate to the Integrate section, and click the New Data Flow button. Select the OpenRouter connector tile, then select the credential that will be used to connect to the OpenRouter instance, and click Next; or, create a new OpenRouter credential for use in this flow.

Endpoint templates

Nexla provides pre-built templates that can be used to rapidly configure data sources to ingest data from common OpenRouter API endpoints. Select the endpoint from which this source will fetch data from the Endpoint pulldown menu. Available endpoint templates are listed in the expandable boxes below.

Chat Completion

This endpoint generates chat completions using OpenRouter's API, allowing you to interact with various AI models for natural language processing and text generation. Use this endpoint when you need to generate responses, complete text, or interact with AI models through a chat interface.

  • Enter the Model name you want to use for generating content in the Model field. The model name should follow the format provider/model-name (e.g., openai/gpt-3.5-turbo, anthropic/claude-3-opus). The default is openai/gpt-3.5-turbo.
  • Enter the System Prompt in the System Prompt field. This provides instructions for the AI model about how it should behave and respond. The default is You are a helpful assistant.
  • Enter the Message or query you want to send to the model in the Message field. This is the user's input that the model will process and respond to.
  • Configure optional parameters to control the model's behavior:

    • Max tokens model param: Set the maximum number of tokens the model should generate. The default is 2048. Higher values allow longer responses but may increase costs.
    • Temperature: Control the randomness of the output. Lower values (e.g., 0.3) make responses more focused and deterministic, while higher values (e.g., 1.0) make responses more creative and varied. The default is 0.3.
    • Top-P: Set the probability threshold for token selection. Higher values (near 1) increase diversity, while lower values (near 0) make the model more conservative. The default is 1.
    • Top-K: Set the number of top tokens to consider. Higher values (e.g., 100) increase diversity, while lower values (e.g., 1) make responses more focused. The default is 32.
  • The endpoint will return the model's response, including the generated text and metadata about the completion.

This endpoint uses POST method and requires your API key for authentication. Different models may have different capabilities and pricing. For a list of available models and their specifications, refer to the OpenRouter API Documentation.

Once the selected endpoint template has been configured, click the Test button to the right of the endpoint selection menu to retrieve a sample of the data that will be fetched. Sample data will be displayed in the Endpoint Test Result panel on the right, allowing you to verify that the source is configured correctly before saving.

Manual configuration

OpenRouter data sources can also be manually configured to ingest data from any valid OpenRouter API endpoint, including endpoints not covered by the pre-built templates, chained API calls, or custom request parameters. Select the Advanced tab at the top of the configuration screen, and follow the instructions in Connect to Any API to configure the API method, endpoint URL, date/time and lookup macros, path to data, metadata, and request headers.

OpenRouter API endpoints typically follow the pattern https://openrouter.ai/api/v1/{endpoint_name} (e.g., chat/completions). For OpenRouter, the API key is automatically included in the request headers from your credential, and Content-Type is typically set to application/json, so you do not need to add these as additional request headers.

Once all of the relevant settings have been configured, click the Create button in the upper right corner of the screen to save and create the new OpenRouter data source. Nexla will now begin ingesting data from the configured endpoint and will organize any data that it finds into one or more Nexsets.

Use as a destination

Click the + icon on the Nexset that will be sent to the OpenRouter destination, and select the Send to Destination option from the menu. Select the OpenRouter connector from the list of available destination connectors, then select the credential that will be used to connect to the OpenRouter organization, and click Next; or, create a new OpenRouter credential for use in this flow.

Endpoint templates

Nexla provides pre-built templates that can be used to rapidly configure destinations to send data to common OpenRouter API endpoints. Select the endpoint to which data will be sent from the Endpoint pulldown menu. Then, click on the template in the list below to expand it, and follow the instructions to configure additional endpoint settings.

Embedding

This endpoint generates text embeddings using OpenRouter's API. Embeddings are vector representations of text that can be used for semantic search, similarity matching, and machine learning applications. Use this endpoint when you need to convert text data into embeddings for downstream processing or analysis.

  • This endpoint accepts JSON data in the request body containing the text to be embedded. Each record will be sent as a separate API request.
  • Ensure your data includes the required fields for embedding generation, such as the text content and model specification, as specified in the OpenRouter API documentation.
  • The endpoint will return embedding vectors that represent the semantic meaning of the input text.

This endpoint uses POST method for generating embeddings. The endpoint accepts JSON data in the request body and does not support batch mode by default, so each record will be sent as a separate API request. For more information about generating embeddings, refer to the OpenRouter Embeddings Documentation.

Manual configuration

OpenRouter destinations can also be manually configured to send data to any valid OpenRouter API endpoint. Select the Advanced tab at the top of the configuration screen, and follow the instructions in Connect to Any API to configure the API method, data format, endpoint URL, request headers, attribute exclusions, record batching, and response webhooks.

OpenRouter API endpoints typically follow the pattern https://openrouter.ai/api/v1/{endpoint_name} (e.g., embeddings). For most OpenRouter API endpoints, the default request body template {message.json} will work correctly, sending the entire record as JSON. For OpenRouter, the API key is automatically included in the request headers from your credential, and Content-Type is typically set to application/json, so you do not need to add these as additional request headers.

Save & activate

Once all endpoint settings have been configured, click the Create button in the upper right corner of the screen to save and create the destination. To send the data to the configured OpenRouter endpoint, open the destination resource menu, and select Activate.

The Nexset data will not be sent to the OpenRouter endpoint until the destination is activated. Destinations can be activated immediately or at a later time, providing full control over data movement.