Skip to main content
Consumer guide

First request

Stream a completion with cURL or an official OpenAI SDK in a few minutes.

1. Create an API key

Sign in, open API keys, and create an inference-scoped key. Its full value is displayed once. Store it in a secret manager, never source control or browser code.

export OPENGRID_API_KEY="mw_..."

2. cURL

curl https://api.opengrid.computer/v1/chat/completions \
  -H "Authorization: Bearer $OPENGRID_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta-llama/Llama-3.1-8B-Instruct",
    "messages": [{"role":"user","content":"Why is the sky blue?"}],
    "stream": true
  }'

3. Python

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.opengrid.computer/v1",
    api_key=os.environ["OPENGRID_API_KEY"],
)

stream = client.chat.completions.create(
    model="meta-llama/Llama-3.1-8B-Instruct",
    messages=[{"role": "user", "content": "Why is the sky blue?"}],
    stream=True,
)
for event in stream:
    print(event.choices[0].delta.content or "", end="")

4. TypeScript

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.opengrid.computer/v1",
  apiKey: process.env.OPENGRID_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "meta-llama/Llama-3.1-8B-Instruct",
  messages: [{ role: "user", content: "Why is the sky blue?" }],
  stream: true,
});
for await (const event of stream) {
  process.stdout.write(event.choices[0]?.delta?.content ?? "");
}

Errors and retries

Errors use the standard OpenAI envelope with error.message, error.type, and error.code. Retry 429, 502, and 503 with exponential backoff and jitter. Do not retry validation or authentication failures.

A node performing inference sees the plaintext prompt and generated tokens. Review the privacy disclosure before sending user data.