POST /v1/chat/completions is the broadest OpenAI-compatible conversation endpoint. Use it for text, multi-turn messages, streaming, and—when supported by the model—vision and tool calls.
Basic request
curl https://api.nbility.ai/v1/chat/completions \
-H "Authorization: Bearer $NBILITY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [
{"role": "system", "content": "Keep the answer concise."},
{"role": "user", "content": "What is an API gateway?"}
]
}'
Use an actual model ID returned by GET /v1/models. Replace the example if it is outside your token's scope.
Common fields
| Field | Type | Required | Description |
|---|---|---|---|
model | string | yes | Model ID |
messages | array | yes | Ordered messages, commonly with system, user, assistant, or tool roles |
stream | boolean | no | When true, normally returns incremental SSE events |
temperature | number | no | Sampling randomness; range and support are model-specific |
top_p | number | no | Nucleus-sampling parameter |
max_tokens | integer | no | Maximum output tokens; some models use a corresponding newer field |
tools | array | no | Tools available to the model |
tool_choice | string | object | no | Controls tool selection |
response_format | object | no | JSON or structured-output configuration, when supported |
user | string | no | End-user identifier for audit purposes |
Nbility preserves compatible request shapes where possible, but providers do not support identical parameters. If a request reports an unsupported parameter, remove it or use the model's native protocol instead of assuming every OpenAI field can be translated.
Python SDK
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["NBILITY_API_KEY"],
base_url="https://api.nbility.ai/v1",
timeout=60.0,
max_retries=2,
)
response = client.chat.completions.create(
model="gpt-5.4",
messages=[{"role": "user", "content": "Give me a two-line summary."}],
)
print(response.choices[0].message.content)
Streaming
stream = client.chat.completions.create(
model="gpt-5.4",
messages=[{"role": "user", "content": "Tell me a very short story."}],
stream=True,
)
for chunk in stream:
text = chunk.choices[0].delta.content
if text:
print(text, end="", flush=True)
Image input
Use this shape only with a vision-capable model:
{
"model": "YOUR_VISION_MODEL",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image."},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}]
}
Production clients should also set connection and overall timeouts plus a bounded retry policy; see Errors and retries.