Permintaan Teks & Kod
Contoh ini menggunakan endpoint Serasi OpenAI Flex247.
Sembang asas
bash
curl https://api.noflex.work/v1/chat/completions \
-H "Authorization: Bearer sk-your-flex247-key" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model-id",
"messages": [{"role":"user","content":"Write one product tagline."}]
}'Arahan sistem
json
{
"model": "your-model-id",
"messages": [
{"role": "system", "content": "Act as a senior code reviewer. State risks first, then propose the smallest safe change."},
{"role": "user", "content": "Review the following function."}
]
}Sembang berbilang giliran
Sertakan sejarah yang perlu dikekalkan:
js
const messages = [
{ role: 'user', content: 'Suggest three project names.' },
{ role: 'assistant', content: 'Nova, Orbit, Canvas' },
{ role: 'user', content: 'Choose the second and write a tagline.' }
]
const result = await client.chat.completions.create({
model: 'your-model-id',
messages
})Output JSON
Bagi model yang menyokong output berstruktur, minta JSON dan tetap sahkan skema dalam produksi:
json
{
"model": "your-model-id",
"messages": [
{"role":"user","content":"Return JSON with title, summary and tags."}
],
"response_format": {"type":"json_object"}
}Tamat masa dan percubaan semula
- Cuba semula tamat masa, sambungan terputus dan ralat
5xxtertentu dalam jumlah terhad. - Jangan cuba
401berulang kali; semak kunci dahulu. - Gunakan exponential backoff untuk
429dan kurangkan concurrency. - Gunakan penstriman untuk tugas panjang apabila disokong.