サンプル
curl
コマンドラインから 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": "簡潔に回答してください。"},
{"role": "user", "content": "一文で要約: CanalAPI は多数の LLM を集約します。"}
]
}'ストリーミング
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": "川を題材にした俳句をストリーミングで。"}]
}'--no-buffer は必須です。指定しないと curl が応答をバッファリングし、増分出力が見えません。
ファンクションコール(ツール)
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": "指定都市の現在の天気を取得します。",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}],
"messages": [{"role": "user", "content": "東京の今の天気は?"}]
}'