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¶
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¶
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:
- Agentic Development — set up LangChain, LlamaIndex, or Claude Code with PAIS
- Worked Examples — full runnable examples for common research patterns
- Inference API Reference — full endpoint documentation