> ## Documentation Index
> Fetch the complete documentation index at: https://1router.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup

> 1 Interface for all AI models.

<img className="block" src="https://mintcdn.com/1routercom/BFY4OsWLBmUaLi3o/images/1router-qrcode.png?fit=max&auto=format&n=BFY4OsWLBmUaLi3o&q=85&s=cf286b35a3d24a7c9853b0258041b137" alt="1Router X.com" width="200" data-path="images/1router-qrcode.png" />

## Principles

In the future, there will be many models - from language to image - and providers. **How will you pick the best one?**

<CardGroup cols={2}>
  <Card title="Price and Performance" icon="dollar-sign" href="#">
    1Router finds the best prices and speeds from various providers, letting you decide what matters most.
  </Card>

  <Card title="Seamless API" icon="code" href="#">
    Switch between models easily without changing your code, and let users choose and pay for their own options.
  </Card>

  <Card title="Usage Over Evals" icon="chart-line" href="#">
    The most popular models will be used more often. Compare them based on real usage instead of flawed evaluations.
  </Card>

  <Card title="Chatroom Feature" icon="comments" href="#">
    Interact with multiple models at once in the Chatroom for a more dynamic experience.
  </Card>
</CardGroup>

## Quick Start

To get started, you can use 1Router via API like this:

<CodeGroup>
  ```typescript typescript theme={null}
  fetch("https://1router.com/api/v1/chat/completions", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${1ROUTER_API_KEY}`,
      "HTTP-Referer": `${YOUR_SITE_URL}`, // Optional, for including your app on 1router.com rankings.
      "X-Title": `${YOUR_SITE_NAME}`, // Optional. Shows in rankings on 1router.com.
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "model": "meta-llama/llama-3.1-405b-instruct",
      "messages": [
        {
          "role": "user",
          "content": "What is the meaning of life?"
        }
      ]
    })
  });

  ```

  ```python python theme={null}
  import requests
  import json

  response = requests.post(
      url="https://1router.com/api/v1/chat/completions",
      headers={
          "Authorization": f"Bearer {1ROUTER_API_KEY}",
          "HTTP-Referer": f"{YOUR_SITE_URL}",  # Optional, for including your app on 1router.com rankings.
          "X-Title": f"{YOUR_APP_NAME}",  # Optional. Shows in rankings on 1router.com.
          "Content-Type": "application/json"
      },
      data=json.dumps({
          "model": "meta-llama/llama-3.1-405b-instruct",
          "messages": [
              {
                  "role": "user",
                  "content": "What is the meaning of life?"
              }
          ]
      })
  )

  ```

  ```ruby ruby theme={null}
  require "open_router"

  OpenRouter.configure do |config|
    config.access_token = ENV["ACCESS_TOKEN"]
    config.site_name = "YOUR_APP_NAME"
    config.site_url = "YOUR_SITE_URL"
  end

  OpenRouter::Client.new.complete(
    model: "meta-llama/llama-3.1-405b-instruct",
    messages: [
      {
        "role": "user",
        "content": "What is the meaning of life?"
      }
    ]
  ).then do |response|
    puts response.dig("choices", 0, "message", "content")
  end


  ```

  ```bash shell theme={null}
  curl https://1router.com/api/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $1ROUTER_API_KEY" \
    -d '{
    "model": "meta-llama/llama-3.1-405b-instruct",
    "messages": [
      {
        "role": "user",
        "content": "What is the meaning of life?"
      }
    ]
  }'


  ```
</CodeGroup>

You can also use 1Router with OpenAI's client API:

<CodeGroup>
  ```typescript typescript theme={null}
  import OpenAI from "openai";

  const openai = new OpenAI({
    baseURL: "https://1router.com/api/v1",
    apiKey: $ROUTER_API_KEY,
    defaultHeaders: {
      "HTTP-Referer": $YOUR_SITE_URL, // Optional, for including your app on 1router.com rankings.
      "X-Title": $YOUR_SITE_NAME, // Optional. Shows in rankings on 1router.com.
    }
  });

  async function main() {
    const completion = await openai.chat.completions.create({
      model: "meta-llama/llama-3.1-405b-instruct",
      messages: [
        {
          "role": "user",
          "content": "What is the meaning of life?"
        }
      ]
    });

    console.log(completion.choices[0].message);
  }

  main();


  ```

  ```python python theme={null}
  from openai import OpenAI
  from os import getenv

  # gets API Key from environment variable OPENROUTER_API_KEY
  client = OpenAI(
      base_url="https://1router.com/api/v1",
      api_key=getenv("1ROUTER_API_KEY"),
  )

  completion = client.chat.completions.create(
      extra_headers={
          "HTTP-Referer": YOUR_SITE_URL,  # Optional, for including your app on 1router.com rankings.
          "X-Title": YOUR_APP_NAME,  # Optional. Shows in rankings on 1router.com.
      },
      model="meta-llama/llama-3.1-405b-instruct",
      messages=[
          {
              "role": "user",
              "content": "What is the meaning of life?"
          }
      ]
  )

  print(completion.choices[0].message.content)

  ```
</CodeGroup>
