Gumawa ng kumpletong chat
Magpadala ng kahilingan sa ShareAI chat-completions gamit ang Bearer API key at unawain ang suportadong modelo, mga mensahe at stream fields.
Sa pahinang ito
https://api.shareai.now/api/v1/chat/completionsPatakbuhin ang isang chat request gamit ang napiling modelo.
- Base URL
https://api.shareai.now- Pagpapatunay
- Bearer API key
Ito ang default na landas ng integrasyon para sa mga kahilingang binayaran at awtorisado ng iyong API-key workspace. Ang mga limitasyon ng modelo at provider ng key ay nalalapat sa alokasyon, kabilang ang pinapayagang fallback paths.
Katawan ng kahilingan#
| Patlang | Uri | Kahulugan |
|---|---|---|
model | string, kinakailangan | Eksaktong magagamit na identifier ng modelo. Kopyahin ito mula sa Models. |
messages | array | Mga mensahe ng pag-uusap na naglalaman ng role at content. |
stream | boolean | false ay nagbabalik ng isang JSON result; true ay humihiling ng server-sent events. |
Gamitin ang nilalaman ng text message. Magpadala ng mga role tulad ng system, user at assistant naaangkop sa pag-uusap. Isama ang kasaysayan ng pag-uusap na nais mong gamitin ng modelo; huwag ipagpalagay na ang mga kahilingan ay nagbabahagi ng nakaimbak na pag-uusap.
cURL
curl --fail-with-body --request POST \
"https://api.shareai.now/api/v1/chat/completions" \
-H "Authorization: Bearer $SHAREAI_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "MODEL_IDENTIFIER",
"messages": [
{
"role": "system",
"content": "Be concise and helpful."
},
{
"role": "user",
"content": "Give me three ideas for a local community event."
}
],
"stream": false
}'
Python
import json
import os
import urllib.request
headers = {"Authorization": "Bearer " + os.environ["SHAREAI_API_KEY"]}
headers["Content-Type"] = "application/json"
payload = {'model': 'MODEL_IDENTIFIER', 'messages': [{'role': 'system', 'content': 'Be concise and helpful.'}, {'role': 'user', 'content': 'Give me three ideas for a local community event.'}], 'stream': False}
data = json.dumps(payload).encode()
request = urllib.request.Request('https://api.shareai.now/api/v1/chat/completions', data=data, headers=headers, method='POST')
with urllib.request.urlopen(request, timeout=60) as response:
print(json.load(response))
TypeScript
const url = "https://api.shareai.now/api/v1/chat/completions";
const headers: Record = {
Authorization: `Bearer ${process.env.SHAREAI_API_KEY}`,
};
headers["Content-Type"] = "application/json";
const payload = {
"model": "MODEL_IDENTIFIER",
"messages": [
{
"role": "system",
"content": "Be concise and helpful."
},
{
"role": "user",
"content": "Give me three ideas for a local community event."
}
],
"stream": false
};
const response = await fetch(url, { method: "POST", headers, body: JSON.stringify(payload) });
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
console.log(await response.json());
Tugon#
Ang isang nakumpletong non-streaming na resulta ay nagtatakda done sa true at ibinabalik ang nabuong teksto sa message.content. Ang top level ay nagdadala rin done_reason at consumption_type. Ang streaming ay gumagamit ng ibang, chat-completion-chunk format. Huwag ipagpalagay na ang non-streaming na resulta ay may OpenAI-style choices array.
JSON
{
"done": true,
"done_reason": "stop",
"consumption_type": "credits",
"message": {
"role": "assistant",
"content": "Here are three ideas for your community event.",
"done": true,
"done_reason": "stop"
}
}
Ito ay isang ilustratibong nakumpletong resulta; ang consumption_type ay naglalarawan ng aktwal na mode ng alokasyon. Suriin ang top-level error kahit na ang HTTP status ay 200. Ang no-device na resulta ay kasalukuyang gumagamit ng error.code = no_device na may HTTP 200.
Mga limitasyon ng modelo at provider#
Ang isang key ay maaaring limitado sa mga partikular na modelo at execution providers. Kung ang access ay tinanggihan, suriin ang impormasyon ng key at i-update ang key sa Console lamang kung ang workspace na nagmamay-ari ay nilalayon na bigyan ang access na iyon.
Streaming o awtorisasyon ng customer#
Huling na-update noong Setyembre 15, 2026