Developer Guide
Quickstart
A 5-minute, copy-pasteable integration with CanalAPI.
Prerequisites
- An API key. See Getting Started.
- The Base URL for your account (shown in the console).
export CANALAPI_BASE_URL="https://api.canalapi.com/v1"
export CANALAPI_API_KEY="sk-..."curl
curl "$CANALAPI_BASE_URL/chat/completions" \
-H "Authorization: Bearer $CANALAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "Hello"}
]
}'JavaScript (Node 22+)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.CANALAPI_API_KEY,
baseURL: process.env.CANALAPI_BASE_URL,
});
const completion = await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(completion.choices[0].message.content);Python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["CANALAPI_API_KEY"],
base_url=os.environ["CANALAPI_BASE_URL"],
)
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)What next
- Add streaming for responsive UIs.
- Handle errors and rate limits before going to production.
- Pick the right model for your task.