Create a chat completion
Send a ShareAI chat-completions request with a Bearer API key and understand the supported model, messages and stream fields.
On this page
https://api.shareai.now/api/v1/chat/completionsRun a chat request using the selected model.
- Base URL
https://api.shareai.now- Authentication
- Bearer API key
This is the default integration path for requests paid and authorized by your API-key workspace. The key’s model and provider restrictions apply to allocation, including permitted fallback paths.
Request body#
| Field | Type | Meaning |
|---|---|---|
model | string, required | Exact available model identifier. Copy it from Models. |
messages | array | Conversation messages containing role and content. |
stream | boolean | false returns one JSON result; true requests server-sent events. |
Use text message content. Send roles such as system, user and assistant as appropriate to the conversation. Include the conversation history you want the model to use; do not assume requests share a stored conversation.
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());
Response#
A completed non-streaming result sets done to true and returns the generated text at message.content. The top level also carries done_reason and consumption_type. Streaming uses a different, chat-completion-chunk format. Do not assume the non-streaming result has an 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"
}
}
This is an illustrative completed result; consumption_type describes the actual allocation mode. Check for a top-level error even when HTTP status is 200. A no-device result currently uses error.code = no_device with HTTP 200.
Model and provider restrictions#
A key may be limited to specific models and execution providers. If access is denied, inspect key information and update the key in Console only if the owning workspace intends to grant that access.
Streaming or customer authorization#
Last updated September 15, 2026