Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.routing.run/llms.txt

Use this file to discover all available pages before exploring further.

Use https://api.routing.run as the base URL for direct HTTP calls. Pass your key with X-API-Key.

Python

import base64
import os

import requests

API_KEY = os.environ["ROUTING_RUN_API_KEY"]
BASE_URL = "https://api.routing.run"

headers = {"X-API-Key": API_KEY}

tts_response = requests.post(
    f"{BASE_URL}/v1/audio/speech",
    headers=headers,
    json={
        "model": "route/eleven-flash-v2.5",
        "input": "Hello world",
        "voice": "JBFqnCBsd6RMkjVDRZzb",
    },
    timeout=60,
)
tts_response.raise_for_status()

with open("output.mp3", "wb") as file:
    file.write(tts_response.content)

image_response = requests.post(
    f"{BASE_URL}/v1/images/generations",
    headers=headers,
    json={
        "model": "route/flux-1-schnell",
        "prompt": "A cute cat",
        "width": 1024,
        "height": 1024,
    },
    timeout=120,
)
image_response.raise_for_status()

data = image_response.json()
image_data = data["data"][0]["b64_json"]

with open("cat.png", "wb") as file:
    file.write(base64.b64decode(image_data))

TypeScript

const apiKey = process.env.ROUTING_RUN_API_KEY;
const baseUrl = "https://api.routing.run";

if (!apiKey) {
  throw new Error("ROUTING_RUN_API_KEY is required");
}

const headers = { "X-API-Key": apiKey };

const ttsResponse = await fetch(`${baseUrl}/v1/audio/speech`, {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "route/eleven-flash-v2.5",
    input: "Hello world",
    voice: "JBFqnCBsd6RMkjVDRZzb",
  }),
});

if (!ttsResponse.ok) {
  throw new Error(await ttsResponse.text());
}

const audioBytes = await ttsResponse.arrayBuffer();
await Bun.write("output.mp3", audioBytes);

const imageResponse = await fetch(`${baseUrl}/v1/images/generations`, {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "route/flux-1-schnell",
    prompt: "A cute cat",
  }),
});

if (!imageResponse.ok) {
  throw new Error(await imageResponse.text());
}

const imageData = await imageResponse.json();
console.log(imageData.data[0].b64_json);

const embeddingResponse = await fetch(`${baseUrl}/v1/embeddings`, {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "route/cohere-embed-v3-english-3",
    input: "The quick brown fox jumps over the lazy dog",
  }),
});

if (!embeddingResponse.ok) {
  throw new Error(await embeddingResponse.text());
}

const embeddingData = await embeddingResponse.json();
console.log(embeddingData.data[0].embedding);

const rerankResponse = await fetch(`${baseUrl}/v1/rerank`, {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "route/cohere-rerank-v4.0-pro",
    query: "best database for vector search",
    documents: [
      "PostgreSQL supports pgvector for vector search.",
      "Redis is often used as an in-memory cache.",
      "SQLite is a small embedded relational database.",
    ],
    top_n: 2,
  }),
});

if (!rerankResponse.ok) {
  throw new Error(await rerankResponse.text());
}

const rerankData = await rerankResponse.json();
console.log(rerankData.results);

const summaryResponse = await fetch(`${baseUrl}/v1/chat/completions`, {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "route/mistral-medium-2505",
    messages: [
      { role: "system", content: "Summarize the user text into 5 bullet points." },
      { role: "user", content: "<long document text here>" },
    ],
    max_tokens: 700,
  }),
});

if (!summaryResponse.ok) {
  throw new Error(await summaryResponse.text());
}

const summaryData = await summaryResponse.json();
console.log(summaryData.choices[0].message.content);
For chat completions with SDK support, use the OpenAI compatible API.