curl https://api.ithu.tw/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-oss-120b",
"messages": [
{ "role": "system", "content": "你是一個來自東海大學的有用助理。" },
{ "role": "user", "content": "請介紹東海大學的路思義教堂。" }
]
}'
import os, requests, json
API_KEY = "YOUR_API_KEY"
API_BASE_URL = "https://api.ithu.tw/v1"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
}
data = {
"model": "gpt-oss-120b",
"messages": [
{"role": "system", "content": "你是一個來自東海大學的有用助理。"},
{"role": "user", "content": "請介紹東海大學的路思義教堂。"}
]
}
response = requests.post(
f"{API_BASE_URL}/chat/completions",
headers=headers,
data=json.dumps(data)
)
if response.status_code == 200:
print(response.json()['choices'][0]['message']['content'])
else:
print(f"請求失敗,狀態碼: {response.status_code}")
<?php
$apiKey = "YOUR_API_KEY";
$apiBaseUrl = "https://api.ithu.tw/v1";
$payload = [
"model" => "gpt-oss-120b",
"messages" => [
["role" => "system", "content" => "你是一個來自東海大學的有用助理。"],
["role" => "user", "content" => "請介紹東海大學的路思義教堂。"],
],
];
$ch = curl_init("{$apiBaseUrl}/chat/completions");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey,
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
echo $data['choices'][0]['message']['content'];
} else {
echo "請求失敗,狀態碼: {$httpCode}\n";
}
const API_KEY = 'YOUR_API_KEY';
const API_BASE_URL = 'https://api.ithu.tw/v1';
async function run() {
const res = await fetch(`${API_BASE_URL}/chat/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
body: JSON.stringify({
model: 'gpt-oss-120b',
messages: [
{ role: 'system', content: '你是一個來自東海大學的有用助理。' },
{ role: 'user', content: '請介紹東海大學的路思義教堂。' },
],
}),
});
if (!res.ok) {
console.error('請求失敗,狀態碼:', res.status);
return;
}
const data = await res.json();
console.log(data.choices[0].message.content);
}
run().catch(console.error);