Skip to content

Your First API Call

Verify your API key and make a test inference call. The PAIS API is OpenAI-compatible, so any OpenAI SDK or tool works out of the box.

Prerequisites

  • A PAIS API key (see Getting an API Key)
  • Python 3.10+ with the OpenAI SDK: pip install openai

Environment setup

export PAIS_API_KEY="pais-sk-..."
export PAIS_API_BASE="https://api.pais.auckland.ac.nz/v1"

Test with curl

The quickest check — no Python needed:

curl "${PAIS_API_BASE}/chat/completions" \
  -H "Authorization: Bearer ${PAIS_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama-3-1-8b",
    "messages": [{"role": "user", "content": "Say hello in one sentence."}],
    "max_tokens": 50
  }'

Expected response:

{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "llama-3-1-8b",
  "choices": [{
    "message": {
      "role": "assistant",
      "content": "Hello! I'm happy to help you today."
    },
    "finish_reason": "stop"
  }],
  "usage": { "prompt_tokens": 14, "completion_tokens": 12, "total_tokens": 26 }
}

Test with Python

import os
from openai import OpenAI

client = OpenAI(
    base_url=os.environ["PAIS_API_BASE"],
    api_key=os.environ["PAIS_API_KEY"],
)

response = client.chat.completions.create(
    model="llama-3-1-8b",
    messages=[
        {"role": "system", "content": "You are a helpful research assistant."},
        {"role": "user", "content": "What is transfer learning in one paragraph?"},
    ],
)

print(response.choices[0].message.content)

Test embeddings

embedding = client.embeddings.create(
    model="qwen3-vl-embedding-8b",
    input="The L40S GPU has 48 GB of VRAM.",
)
print(f"Embedding dimension: {len(embedding.data[0].embedding)}")

List available models

models = client.models.list()
for m in models.data:
    print(m.id)

Troubleshooting

Error Likely cause Fix
401 Unauthorized Invalid or missing API key Check PAIS_API_KEY is set correctly
404 Not Found Wrong base URL Check PAIS_API_BASE points to /v1
model not found Wrong model name Use client.models.list() to see available IDs
503 / timeout Model not loaded or GPU busy Wait 30 s and retry; contact PAIS team if persistent

Next steps

You're ready. Where to go from here: