Skip to main content

OpenRouter Data Source

The OpenRouter connector enables you to ingest data from the OpenRouter API, which provides access to multiple AI models for chat completions and text generation. This connector is particularly useful for AI applications, natural language processing workflows, and content generation systems that need to integrate with various AI models through a unified interface. Follow the instructions below to create a new data flow that ingests data from an OpenRouter source in Nexla.
openrouter_api.png

OpenRouter

Create a New Data Flow

  1. To create a new data flow, navigate to the Integrate section, and click the New Data Flow button. Then, select the desired flow type from the list, and click the Create button.

  2. Select the OpenRouter connector tile from the list of available connectors. 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.

  3. In Nexla, OpenRouter data sources can be created using pre-built endpoint templates, which expedite source setup for common OpenRouter API endpoints. Each template is designed specifically for the corresponding OpenRouter API endpoint, making source configuration easy and efficient.
    • To configure this source using a template, follow the instructions in Configure Using a Template.

    OpenRouter sources can also be configured manually, allowing you to ingest data from OpenRouter API endpoints not included in the pre-built templates or apply further customizations to exactly suit your needs.
    • To configure this source manually, follow the instructions in Configure Manually.

Configure Using a Template

Nexla provides pre-built templates that can be used to rapidly configure data sources to ingest data from common OpenRouter API endpoints. Each template is designed specifically for the corresponding OpenRouter API endpoint, making data source setup easy and efficient.

Endpoint Settings

  • 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. Click on an endpoint to see more information about it and how to configure your data source for this endpoint.

    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.

Endpoint Testing

Once the selected endpoint template has been configured, Nexla can retrieve a sample of the data that will be fetched according to the current settings. This allows users to verify that the source is configured correctly before saving.

  • To test the current endpoint configuration, click the Test button to the right of the endpoint selection menu. Sample data will be fetched & displayed in the Endpoint Test Result panel on the right.

  • If the sample data is not as expected, review the selected endpoint and associated settings, and make any necessary adjustments. Then, click the Test button again, and check the sample data to ensure that the correct information is displayed.

Configure Manually

OpenRouter data sources can be manually configured to ingest data from any valid OpenRouter API endpoint. Manual configuration provides maximum flexibility for accessing endpoints not covered by pre-built templates or when you need custom API configurations.

With manual configuration, you can also create more complex OpenRouter sources, such as sources that use chained API calls or sources that require custom request parameters.

API Method

  1. To manually configure this source, select the Advanced tab at the top of the configuration screen.

  2. Select the API method that will be used for calls to the OpenRouter API from the Method pulldown menu. The most common methods are:

    • POST: For chat completions and other AI model interactions (most common for OpenRouter)

API Endpoint URL

  1. Enter the URL of the OpenRouter API endpoint from which this source will fetch data in the Set API URL field. This should be the complete URL including the protocol (https://) and the API path. OpenRouter API endpoints typically follow the pattern https://openrouter.ai/api/v1/{endpoint_name}, where {endpoint_name} is the specific API endpoint (e.g., chat/completions).

Ensure the API endpoint URL is correct and accessible with your current credentials. You can test the endpoint using the Test button after configuring the URL. The endpoint URL should use the base URL https://openrouter.ai/api/v1/ followed by the endpoint name. For more information about OpenRouter API endpoints, refer to the OpenRouter API Documentation.

Path to Data

Optional

If only a subset of the data that will be returned by API endpoint is needed, you can designate the part(s) of the response that should be included in the Nexset(s) produced from this source by specifying the path to the relevant data within the response.

  • To specify which data should be treated as relevant in responses from this source, enter the path to the relevant data in the Set Path to Data in Response field.

    • For responses in JSON format enter the JSON path that points to the object or array that should be treated as relevant data. JSON paths use dot notation (e.g., $.choices[*] to access the choices array in a chat completion response).

Request Headers

Optional
  • If Nexla should include any additional request headers in API calls to this source, enter the headers & corresponding values as comma-separated pairs in the Request Headers field (e.g., header1:value1,header2:value2). Additional headers are often required for API versioning, content type specifications, or custom authentication requirements.

    You do not need to include any headers already present in the credentials. Common headers like Authorization, Content-Type, and Accept are typically handled automatically by Nexla based on your credential configuration. For OpenRouter, the API key is automatically included in the request headers from your credential, and Content-Type is typically set to application/json.

Endpoint Testing

After configuring all settings for the selected endpoint, Nexla can retrieve a sample of the data that will be fetched according to the current configuration. This allows users to verify that the source is configured correctly before saving.

  • To test the current endpoint configuration, click the Test button to the right of the endpoint selection menu. Sample data will be fetched & displayed in the Endpoint Test Result panel on the right.

  • If the sample data is not as expected, review the selected endpoint and associated settings, and make any necessary adjustments. Then, click the Test button again, and check the sample data to ensure that the correct information is displayed.

Save & Activate the Source

  1. Once all of the relevant steps in the above sections have been completed, 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.