Search sandriver-ai

21 destinations

DOCUMENTATION

Quickstart

From a model to your first request.

Local sandbox guide. These examples are not executed by this page. Real providers and payment collection are not connected.

1. Choose a published model

Read the model directory for available IDs, limits and USD prices. The example below uses a sandbox fixture; select a model actually published in your environment.

Explore models →

2. Create an API key

Sign in to your workspace and create a key with the model permissions and spending limit your application needs. Keep it on your server.

Open API keys →

3. Read a completed response

Save the example as request.mjs and run it with Node 24. Privately set RELAY_API_KEY and RELAY_OPERATION_ID on your server. Keep the same operation ID for the same body; a new body needs a new ID. This sandbox example caps the request at 10,000 micro-USD ($0.01).

JavaScript · Server side
// Save as request.mjs and run with Node 24. Set the two environment variables privately.
const apiKey = process.env.RELAY_API_KEY;
const operationId = process.env.RELAY_OPERATION_ID;
if (!apiKey || !operationId) throw new Error("Set RELAY_API_KEY and a stable RELAY_OPERATION_ID on your server");
const response = await fetch("https://sandriver-ai.com/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + apiKey,
    "Content-Type": "application/json",
    "Idempotency-Key": operationId
  },
  body: JSON.stringify({
  "model": "sandbox/token-demo",
  "messages": [
    {
      "role": "user",
      "content": "Explain how an API works."
    }
  ],
  "max_tokens": 32,
  "maximum_micros": 10000
})
});
const requestId = response.headers.get("x-request-id");
// Save this ID and the original operation ID. A failed/unknown receipt is NOT permission for a replacement request.
console.log("Original request:", requestId, "HTTP:", response.status);
const result = await response.json();
console.log(JSON.stringify(result, null, 2));
if (!response.ok) throw new Error(result.error?.message || "Request refused");
if (response.status === 202) {
  console.log("Execution or metering is unresolved. Keep the original request and reservation; do not submit a replacement.");
}
// Read-only recovery: GET https://sandriver-ai.com/requests/{original-request-id} with the same Authorization header.
// No automatic POST retry. A new payload requires a new operation ID and its own confirmed cost limit.