OpenRouter Innovation Release

Model names: openrouter_chat, openrouter_embeddings

About OpenRouter

OpenRouter is a unified API gateway that provides access to over 200 AI models from multiple providers, including OpenAI, Anthropic, Google, Meta, and many others. It offers a single API endpoint to access models from different providers, simplifying integration and allowing you to switch between models without changing your code.

OpenRouter supports both chat/completion models and embedding models, making it a versatile choice for various AI tasks.

Supported aidb operations

openrouter_chat

  • decode_text
  • decode_text_batch

openrouter_embeddings

  • encode_text
  • encode_text_batch

Supported models

Any model available through OpenRouter. See the OpenRouter models page for a complete list of available models.

  • openai/gpt-4o
  • anthropic/claude-3.5-sonnet
  • google/gemini-pro
  • meta-llama/llama-3.1-70b-instruct
  • openai/text-embedding-3-small
  • openai/text-embedding-3-large

Creating an OpenRouter chat model

You can create an OpenRouter chat model using the aidb.create_model function.

SELECT aidb.create_model(
  'my_openrouter_chat',
  'openrouter_chat',
  aidb.openrouter_chat_config(model => 'anthropic/claude-3.5-sonnet'),
  '{"api_key": "sk-or-v1-abc123..."}'::JSONB
);

Creating an OpenRouter embeddings model

SELECT aidb.create_model(
  'my_openrouter_embeddings',
  'openrouter_embeddings',
  aidb.openrouter_embeddings_config(model => 'openai/text-embedding-3-small'),
  '{"api_key": "sk-or-v1-abc123..."}'::JSONB
);

Running the models

Chat model

SELECT aidb.decode_text('my_openrouter_chat', 'Why is the sky blue?');

Embeddings model

SELECT aidb.encode_text('my_openrouter_embeddings', 'Hello, world!');

Model configuration settings

openrouter_chat configuration

The following configuration settings are available for OpenRouter chat models:

  • model The OpenRouter model to use (required). See available models.
  • api_key The OpenRouter API key. Can also be provided in credentials.
  • url The URL of the OpenRouter API. The default is https://openrouter.ai/api/v1/chat/completions.
  • max_concurrent_requests The maximum number of concurrent requests to make. The default is 25.
  • max_tokens Configuration for the maximum tokens generated. Use aidb.max_tokens_config() to set this.

openrouter_embeddings configuration

The following configuration settings are available for OpenRouter embeddings models:

  • model The OpenRouter embedding model to use (required).
  • api_key The OpenRouter API key. Can also be provided in credentials.
  • url The URL of the OpenRouter API. The default is https://openrouter.ai/api/v1/embeddings.
  • max_concurrent_requests The maximum number of concurrent requests to make. The default is 25.
  • max_batch_size The maximum number of records to send in a single request. The default is 50000.

Model credentials

The following credentials are required:

  • api_key The OpenRouter API key. You can obtain an API key from OpenRouter.

The API key can be provided either in the configuration or in the credentials parameter. If provided in both, the config parameter takes precedence.

-- Using credentials parameter (recommended)
SELECT aidb.create_model(
  'my_openrouter_model',
  'openrouter_chat',
  aidb.openrouter_chat_config(model => 'openai/gpt-4o'),
  '{"api_key": "sk-or-v1-abc123..."}'::JSONB
);