OpenRouter - Unified LLM Interface for ChatGPT, Claude, Gemini avatar

OpenRouter - Unified LLM Interface for ChatGPT, Claude, Gemini

Try for free

1 day trial then $19.99/month - No credit card required now

Go to Store
OpenRouter - Unified LLM Interface for ChatGPT, Claude, Gemini

OpenRouter - Unified LLM Interface for ChatGPT, Claude, Gemini

xyzzy/open-router
Try for free

1 day trial then $19.99/month - No credit card required now

Use the OpenRouter platform to choose the best and most cost effective model for your prompts utilizing a standardized interface (including ChatGPT, Claude, Gemini, Llama, Mistral, and more). See instructions for creating an OpenRouter account and API key.

OpenRouter - A Unified Interface for LLMs

This Apify Actor integrates with OpenRouter, providing access to a diverse array of Large Language Models (LLMs).

The OpenRouter Actor can be used in the Apify console or programmatically via the Apify api.

  • Integration with Other Apify Actors: Use web scraping to collect data and prepare it as training or input data for LLM applications.
  • Clay Users: From within Clay, generate personalized text for a company or contact, conduct company research, determine the ideal customer persona for a company, and more.
  • General Integration with LLMs: Suitable for any use case requiring LLM interaction, whether from another Apify actor or an external application.

Single-Turn Requests

This actor supports single-turn messages due to their simplicity and broad applicability for Apify use cases. Multi-message dialog requests are not supported. However, you may send an array of messages to be processed individually which will use the same model parameters for each message.

Inputs

Review the OpenRouter documentation for more detail on specific parameters, supported models, and links to individual model specifications.

Required Inputs:

  • api_key: Your OpenRouter API key. Encrypted and only used by the Actor at runtime.
  • messages: An array of messages to process individually.
  • model: Model specification (e.g., openai/gpt-4o, google/gemini-flash-1.5, cohere/command-r-plus). Defaults to openrouter/auto.

Optional Parameters:

  • max_tokens: Maximum number of tokens for the model response
  • response_format: Response format type if not text (note: only option is json_object which is not supported by all models)
  • stop: Stop sequence for the model
  • temperature: Sampling temperature
  • top_p: Nucleus sampling probability threshold
  • top_k: Top-k sampling value
  • frequency_penalty: Frequency penalty
  • presence_penalty: Presence penalty
  • repetition_penalty: Repetition penalty
  • seed: Random seed for reproducibility

Example Inputs

Example: Determine the Ideal Customer Persona (ICP) for a Company

  • Scenario: Given details about a company (e.g., from LinkedIn), determine the Ideal Customer Persona (ICP) for the company.
1{
2    "api_key": "your-openrouter-api-key",
3    "messages": [
4        "Your task is to determine the ideal customer persona (ICP) for a company based on their LinkedIn profile. An ICP is a hypothetical description of the type of customer that would be a perfect fit for the company's products or services. Here is the company's description: Apify is a full-stack web scraping and browser automation platform that lets you extract data from websites and automate workflows on the web. Describe the company's ICP in less than 100 words. Only output the description and no summary text, headings, or other markup."
5    ],
6    "model": "openrouter/auto"
7}

Processing

The actor handles OpenRouter API calls using the provided API key:

  • Constructs and sends an API call to OpenRouter for each message in the input array.
  • Processes the response and logs necessary information.
  • Saves the transformed response to the Apify dataset.
  • Note: The actor timeout is set to 100 seconds by default. You may need to increase this based on your use case, including the number of messages per actor run and size of response.

Results

After a successful run, the actor returns the following fields:

  • id: ID assigned by OpenRouter
  • created: Timestamp of the response
  • model: Model used for generating the response
  • content: The generated content
  • finish_reason: Reason why the response finished
  • prompt_tokens: Number of tokens in the prompt
  • completion_tokens: Number of tokens in the completion
  • total_tokens: Total number of tokens used

Example Output:

1[
2  {
3    "id": "gen-hVC5zxaB3vec23r00DNt61hypL7G",
4    "created": "2024-05-15T14:36:07.000Z",
5    "model": "mistralai/mistral-large",
6    "content": "Apify's ideal customer persona is a tech-savvy professional or a business in the data analysis, market research, or e-commerce sectors. They have a strong need for automated web scraping and data extraction to enhance decision-making, monitor competition, or optimize online operations. This persona values efficiency, data quality, and the flexibility to customize scraping processes.",
7    "finish_reason": "stop",
8    "prompt_tokens": 116,
9    "completion_tokens": 70,
10    "total_tokens": 186
11  }
12]

Getting Started

  1. Sign Up for Apify: https://apify.com/
  2. Sign Up for OpenRouter: https://openrouter.ai
  3. Create and Copy Your OpenRouter API Key: https://openrouter.ai/keys
  4. Actor Input: Configure the actor's input with your OpenRouter API key and the required inputs.
  5. Run the Actor: Run the actor from the Apify console or API.

Using this Actor from Another Apify Actor

If you are developing a custom Actor, you can integrate with LLMs by calling the OpenRouter actor via the Apify api. Actor-to-actor integrations using a DatasetId is not yet supported.

For Clay Users

This actor simplifies the configuration required to utilize the OpenRouter API from within Clay. Typically, integrating with OpenRouter requires using the HTTP API enrichment feature, which may not be available on all Clay plans. This actor provides an easier and cost-effective workaround.

  1. Within a Clay contacts table, add an Apify enrichment column.
  2. In the Apify column settings, select open-router from the actor dropdown.
  3. Specify the JSON input data following the example above, add your OpenRouter api_key in the JSON, and replace variables with column references in your Clay table.

Note: Clay has a cell data limit, so set the max_tokens variable in the input accordingly (~4000 tokens)

Use this Clay template to get started. Enter your Apify api key in Clay settings, and your OpenRouter api key in the body of the Apify enrichment column.

Resources

Developer
Maintained by Community

Actor Metrics

  • 1 monthly user

  • 7 stars

  • Created in May 2024

  • Modified 3 months ago