Examples
curl
Send chat completion requests from the command line.
Basic chat completion
curl "$CANALAPI_BASE_URL/chat/completions" \
-H "Authorization: Bearer $CANALAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are concise."},
{"role": "user", "content": "Summarize: CanalAPI aggregates many LLMs."}
]
}'Streaming
curl --no-buffer "$CANALAPI_BASE_URL/chat/completions" \
-H "Authorization: Bearer $CANALAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"stream": true,
"messages": [{"role": "user", "content": "Stream a haiku about rivers."}]
}'--no-buffer is important — without it curl will hold the response in its own buffer and you will not see incremental output.
Function calling (tools)
curl "$CANALAPI_BASE_URL/chat/completions" \
-H "Authorization: Bearer $CANALAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}],
"messages": [{"role": "user", "content": "What is the weather in Tokyo?"}]
}'