Choose execution providers for an API request
Use the ShareAI provider object to select execution providers independently from a model’s creator across all four inference endpoints.
On this page
Set model to the exact creator-based identifier. Add provider when you want to restrict or rank the infrastructure eligible to execute the request. Omitting it uses the default price-ascending policy.
Use one provider#
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 '{
"provider": {
"only": [
"shareai"
],
"allow_fallbacks": false
},
"model": "openai/gpt-5.4",
"messages": [
{
"role": "user",
"content": "Explain model routing in one sentence."
}
]
}'
Python
import json
import os
import urllib.request
headers = {"Authorization": "Bearer " + os.environ["SHAREAI_API_KEY"]}
headers["Content-Type"] = "application/json"
payload = {'provider': {'only': ['shareai'], 'allow_fallbacks': False}, 'model': 'openai/gpt-5.4', 'messages': [{'role': 'user', 'content': 'Explain model routing in one sentence.'}]}
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 = {
"provider": {
"only": [
"shareai"
],
"allow_fallbacks": false
},
"model": "openai/gpt-5.4",
"messages": [
{
"role": "user",
"content": "Explain model routing in one sentence."
}
]
};
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());
Use provider tags shown for the selected model. only is a hard restriction: allowing fallbacks never permits a provider outside this list.
Use the same policy on each inference endpoint#
| Endpoint | Main input field | Choose a model that supports |
|---|---|---|
/api/v1/chat/completions | messages | Chat completion |
/api/v1/responses | input | Responses |
/api/v1/embeddings | input | Embeddings |
/api/v1/images/generations | prompt | Image generation |
The provider policy has the same meaning on these endpoints. Model and provider capabilities differ: a chat model is not automatically an embedding or image model. Copy an eligible identifier for the operation from the catalog; native endpoints require configured support.
Prefer named providers#
JSON
{
"provider": {
"order": [
"PROVIDER_A",
"PROVIDER_B"
],
"allow_fallbacks": false,
"sort": {
"by": "price",
"direction": "asc"
}
}
}
Replace PROVIDER_A and PROVIDER_B with real lowercase provider tags. With this ordered list and fallbacks disabled, only those listed providers are eligible, in that order. The second listed provider can still be selected if the first is unavailable.
Keep credential restrictions#
Your request can narrow an API key’s permitted models and providers. It cannot grant access outside those permissions. OAuth consent, billing eligibility and device availability continue to apply.
Next#
Last updated September 16, 2026