Nbility logoNbility Docs

Search documentation

Search guides and API reference content

POST /v1/chat/completions — OpenAI-compatible chat API

Endpoint

POST /v1/chat/completions

Request Headers

HeaderValue
AuthorizationBearer YOUR_API_KEY
Content-Typeapplication/json

Request Body

NameTypeRequiredDefaultDescription
modelstringyesModel ID, e.g. gpt-4o, gpt-4-turbo, claude-3-5-sonnet-20241022
messagesarrayyesArray of message objects forming the conversation history
streambooleannofalseWhen true, returns server-sent events (SSE) stream
temperaturenumberno1Sampling temperature between 0 and 2. Higher = more random
max_tokensintegernoMaximum number of tokens to generate
top_pnumberno1Nucleus sampling threshold
frequency_penaltynumberno0Penalizes repeated tokens (-2.0 to 2.0)
presence_penaltynumberno0Penalizes tokens based on prior appearance (-2.0 to 2.0)
stopstring | arraynoStop sequences — generation stops when any is encountered
nintegerno1Number of completion choices to generate
userstringnoEnd-user identifier for abuse monitoring

Message Object

NameTypeRequiredDefaultDescription
rolestringyesOne of: "system", "user", "assistant", "tool"
contentstring | arrayyesMessage content. Array format supports multimodal (text + image_url)
namestringnoParticipant name (optional)

Examples

cURL

curl https://api.nbility.dev/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the capital of France?"}
    ]
  }'

Python

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.nbility.dev/v1"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the capital of France?"}
    ]
)
print(response.choices[0].message.content)

Node.js

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://api.nbility.dev/v1',
});

const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'What is the capital of France?' },
  ],
});
console.log(response.choices[0].message.content);

Go

package main

import (
	"context"
	"fmt"
	"github.com/sashabaranov/go-openai"
)

func main() {
	config := openai.DefaultConfig("YOUR_API_KEY")
	config.BaseURL = "https://api.nbility.dev/v1"
	client := openai.NewClientWithConfig(config)

	resp, err := client.CreateChatCompletion(context.Background(), openai.ChatCompletionRequest{
		Model: "gpt-4o",
		Messages: []openai.ChatCompletionMessage{
			{Role: openai.ChatMessageRoleSystem, Content: "You are a helpful assistant."},
			{Role: openai.ChatMessageRoleUser, Content: "What is the capital of France?"},
		},
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Choices[0].Message.Content)
}

Java

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.*;

public class Main {
    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.builder()
            .apiKey("YOUR_API_KEY")
            .baseUrl("https://api.nbility.dev/v1")
            .build();

        ChatCompletion response = client.chat().completions().create(
            ChatCompletionCreateParams.builder()
                .model(ChatModel.GPT_4O)
                .addSystemMessage("You are a helpful assistant.")
                .addUserMessage("What is the capital of France?")
                .build()
        );
        System.out.println(response.choices().get(0).message().content().orElse(""));
    }
}

Streaming Example

cURL

curl https://api.nbility.dev/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "stream": true,
    "messages": [{"role": "user", "content": "Tell me a short story"}]
  }'

Response

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Paris is the capital of France."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 10,
    "total_tokens": 35
  }
}

Multimodal (Vision)

For models that support image input, pass content as an array:

{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "What's in this image?"},
        {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
      ]
    }
  ]
}