Page cover

OpenRouter

OpenRouter is a unified platform that provides developers with seamless access to a wide range of large language models (LLMs) through a single OpenAI-compatible API interface. It enables model interoperability by allowing users to easily route requests between open-source and proprietary models while managing authentication, quotas, and usage tracking in one place.

This tutorial will guide you through utilizing Arcee AI's language models on OpenRouter using an OpenAI-compatible endpoint.


Prerequisites

  • OpenRouter Account

    • If you don't have an account, set one up here.

  • OpenRouter API Key

    • If you don't have an API Key, create one here.

  • openai Python SDK (install using uv or pip)

Quickstart

Run a completion with an Arcee model on OpenRouter

from openai import OpenAI

# Initialize OpenRouter-compatible client
client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key="<OPENROUTER_API_KEY>",
)

# Run a chat completion
completion = client.chat.completions.create(
    model="arcee-ai/trinity-mini",
    messages=[
        {
            "role": "user",
            "content": "What are small language models and how do they compare to LLMs?"
        }
    ]
)

# Print result
print(completion.choices[0].message.content)

Last updated