Skip to main content
Because Pinaivu’s gateway implements the OpenAI API spec, you can use the official OpenAI Python or Node.js SDKs — or any OpenAI-compatible library — by changing only the base URL and your API key. Your existing code, message formats, and tooling all continue to work exactly as before.
No other SDK changes are required. Models, message formats, and streaming all work identically to the standard OpenAI SDK.

Python

1

Install the OpenAI library

Install the official OpenAI Python package using pip.
pip install openai
2

Point the client at Pinaivu

Pass base_url and your sk-pnv-... API key when constructing the client. Everything else stays the same.
from openai import OpenAI

client = OpenAI(
    base_url="https://api.pinaivu.com/v1",
    api_key="sk-pnv-...",
)

response = client.chat.completions.create(
    model="llama3.2:1b",
    messages=[{"role": "user", "content": "Hello!"}],
)

print(response.choices[0].message.content)
You can also set OPENAI_BASE_URL=https://api.pinaivu.com/v1 and OPENAI_API_KEY=sk-pnv-... as environment variables. The SDK picks them up automatically, so you don’t need to pass them explicitly to the constructor.

Node.js / TypeScript

1

Install the OpenAI package

npm install openai
2

Point the client at Pinaivu

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.pinaivu.com/v1",
  apiKey: "sk-pnv-...",
});

const response = await client.chat.completions.create({
  model: "llama3.2:1b",
  messages: [{ role: "user", content: "Hello!" }],
});

console.log(response.choices[0].message.content);

Streaming responses

Pinaivu supports streaming out of the box. Set stream=True in Python (or stream: true in Node.js) and iterate over the chunks exactly as you would with OpenAI.
from openai import OpenAI

client = OpenAI(
    base_url="https://api.pinaivu.com/v1",
    api_key="sk-pnv-...",
)

with client.chat.completions.create(
    model="llama3.2:3b",
    messages=[{"role": "user", "content": "Tell me a short story."}],
    stream=True,
) as stream:
    for chunk in stream:
        delta = chunk.choices[0].delta.content
        if delta:
            print(delta, end="", flush=True)

Environment variables

Store your credentials in a .env file rather than hard-coding them in source files. Most frameworks and the OpenAI SDK load these automatically.
# .env
PINAIVU_API_KEY=sk-pnv-...
OPENAI_BASE_URL=https://api.pinaivu.com/v1
OPENAI_API_KEY=sk-pnv-...
Read the key at runtime using your platform’s standard approach:
import os
api_key = os.environ["PINAIVU_API_KEY"]

Listing available models

Use GET /v1/models to retrieve the current list of models available on the Pinaivu network. This endpoint follows the standard OpenAI models format.
curl https://api.pinaivu.com/v1/models \
  -H "Authorization: Bearer sk-pnv-..."
You can also call it through the SDK:
models = client.models.list()
for model in models.data:
    print(model.id)

Checking usage

Use GET /v1/usage to retrieve your account’s current usage statistics, such as token counts and request volumes. Include your API key in the Authorization header.
curl https://api.pinaivu.com/v1/usage \
  -H "Authorization: Bearer sk-pnv-..."
Every API response from Pinaivu includes a request_id field. You can use this ID to cryptographically verify which GPU node ran your inference. See Verifying Inference to learn how.