Nbility logoNbility Docs

Search documentation

Search guides and API reference content

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

FieldTypeRequiredDescription
modelstringyesModel ID
messagesarrayyesOrdered messages, commonly with system, user, assistant, or tool roles
streambooleannoWhen true, normally returns incremental SSE events
temperaturenumbernoSampling randomness; range and support are model-specific
top_pnumbernoNucleus-sampling parameter
max_tokensintegernoMaximum output tokens; some models use a corresponding newer field
toolsarraynoTools available to the model
tool_choicestring | objectnoControls tool selection
response_formatobjectnoJSON or structured-output configuration, when supported
userstringnoEnd-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.