Quick Start

Send the first request through the R9S distributed AI gateway.

R9S exposes a unified, OpenAI-compatible gateway for model traffic. Use one base URL, one API key, and one request format while R9S handles provider routing, regional access, fallback, usage tracking, and operational visibility.

Prerequisites

  • An R9S API key.
  • A model available to your account.
  • A backend environment where the API key can be stored outside client-side code.

Set the key in your shell:

export R9S_API_KEY="<R9S_API_KEY>"

Verify access

Call the models endpoint before sending application traffic:

curl https://gw.r9s.ai/v1/models \
  -H "Authorization: Bearer $R9S_API_KEY"

The response returns a list of model identifiers that can be used in later requests.

Send a chat request

Use https://gw.r9s.ai/v1 as the gateway base URL. For attribution and reporting, pass HTTP-Referer and X-Title when the request is tied to an application.

curl https://gw.r9s.ai/v1/chat/completions \
  -H "Authorization: Bearer $R9S_API_KEY" \
  -H "Content-Type: application/json" \
  -H "HTTP-Referer: https://example.com" \
  -H "X-Title: Example App" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "user",
        "content": "Explain what R9S does in one sentence."
      }
    ],
    "stream": false
  }'

Use an OpenAI-compatible client

R9S can also be used with clients that support a custom OpenAI-compatible base URL:

import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://gw.r9s.ai/v1",
  apiKey: process.env.R9S_API_KEY,
  defaultHeaders: {
    "HTTP-Referer": "https://example.com",
    "X-Title": "Example App",
  },
});

const completion = await openai.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Hello from R9S." }],
});

Enable streaming

For chat interfaces, set stream: true to receive incremental output events and reduce perceived latency:

{
  "model": "gpt-4o-mini",
  "messages": [
    {
      "role": "user",
      "content": "Write a short product update."
    }
  ],
  "stream": true
}

Production checklist

  • Keep runtime API keys on the server side.
  • Confirm the model is listed by /models.
  • Add attribution headers for app-level reporting.
  • Use streaming for interactive product surfaces.
  • Configure retries for transient 429 and 5xx errors.
  • Monitor latency, error rate, token usage, and spend before increasing traffic.

Next, read Core Concepts and API Reference.