Gumawa ng tugon sa teksto
Gamitin ang ShareAI Responses API para sa stateless text generation, explicit conversation history, at Responses streaming events.
Sa pahinang ito
https://api.shareai.now/api/v1/responsesBumuo ng text response mula sa isang prompt o pag-uusap.
- Base URL
https://api.shareai.now- Pagpapatunay
- Bearer API key o aprubadong OAuth access token
Piliin ang API na ito kapag ang iyong application ay gumagamit ng Responses text-message format. Ibigay ang pag-uusap sa bawat kahilingan; ang mga tugon ay hindi iniimbak para sa susunod na retrieval.
Magpadala ng kahilingan#
cURL
curl --fail-with-body --request POST \
"https://api.shareai.now/api/v1/responses" \
-H "Authorization: Bearer $SHAREAI_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_CHAT_MODEL",
"input": "Explain semantic search in two sentences.",
"instructions": "Use plain language.",
"store": false,
"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': 'YOUR_CHAT_MODEL', 'input': 'Explain semantic search in two sentences.', 'instructions': 'Use plain language.', 'store': False, 'stream': False}
data = json.dumps(payload).encode()
request = urllib.request.Request('https://api.shareai.now/api/v1/responses', 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/responses";
const headers: Record = {
Authorization: `Bearer ${process.env.SHAREAI_API_KEY}`,
};
headers["Content-Type"] = "application/json";
const payload = {
"model": "YOUR_CHAT_MODEL",
"input": "Explain semantic search in two sentences.",
"instructions": "Use plain language.",
"store": false,
"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());
Mga field ng kahilingan#
| Patlang | Halaga |
|---|---|
model | Isang available na chat model na pinapayagan ng iyong kredensyal. |
input | Isang hindi bakanteng string, o hanggang 256 text messages. |
instructions | Opsyonal na mga system instructions na idinagdag sa simula ng pag-uusap. |
store | false; hindi sinusuportahan ang pag-iimbak ng mga tugon. |
stream | false para sa JSON o true para sa Responses SSE events. |
Ipagpatuloy ang isang pag-uusap#
Ipadala ang mga naunang mensahe sa input kasabay ng susunod na mensahe ng user. Ang mga suportadong role ay user, assistant, system at developer. Ang mga developer instructions ay gumagamit ng system role internally. Ang nilalaman ng mensahe ay maaaring text o input_text/output_text mga bahagi.
JSON
{
"model": "YOUR_CHAT_MODEL",
"input": [
{
"role": "user",
"content": "What is semantic search?"
},
{
"role": "assistant",
"content": "It finds results by meaning rather than exact words."
},
{
"role": "user",
"content": "Give one example."
}
],
"store": false
}
Basahin ang resulta#
Ang JSON response ay isang response object. Basahin ang assistant text mula sa output[].content[] mga entry na may type output_text. Suriin ang response status: completed ay isang tapos na tugon; incomplete maaaring magpahiwatig ng token limit. Ang pampublikong usage ay kasalukuyang null; gamitin ang Console Usage upang suriin ang naprosesong paggamit.
Mag-stream ng tugon#
Itakda stream: true at i-parse ang SSE. Kasama sa mga events ang response.created, response.output_text.delta at isang terminal response.completed, response.incomplete or response.failed. Idagdag ang text deltas nang sunod-sunod at i-handle ang terminal status nang malinaw.
Suportadong subset#
Sinusuportahan ng endpoint na ito ang text generation. Ang mga nakaimbak na tugon, previous_response_id, pagkuha/pagtanggal, mga tool, input ng imahe, mga background request at mga setting ng pagbuo tulad ng temperature ay hindi suportado at tinatanggihan. Para sa mga setting ng pagbuo na batay sa mensahe na sinusuportahan ng Chat Completions, gamitin Mga Kumpletong Chat.
Gumamit ng OAuth access token#
Palitan ang API key sa Authorization header ng isang aprubadong OAuth access token. Ang surcharge saklaw at tinatanggap na plano ng paggamit ay kinakailangan para sa inference na pinondohan ng account. Ang mga saklaw na pang-identidad lamang ay hindi nagbibigay pahintulot sa paggastos. Tingnan ang mga saklaw at pahintulot.
Huling na-update noong Setyembre 15, 2026