POST /v1/chat/completions — OpenAI-compatible chat API
POST /v1/chat/completions
| Header | Value |
|---|
Authorization | Bearer YOUR_API_KEY |
Content-Type | application/json |
| Name | Type | Required | Default | Description |
|---|
model | string | yes | | Model ID, e.g. gpt-4o, gpt-4-turbo, claude-3-5-sonnet-20241022 |
messages | array | yes | | Array of message objects forming the conversation history |
stream | boolean | no | false | When true, returns server-sent events (SSE) stream |
temperature | number | no | 1 | Sampling temperature between 0 and 2. Higher = more random |
max_tokens | integer | no | | Maximum number of tokens to generate |
top_p | number | no | 1 | Nucleus sampling threshold |
frequency_penalty | number | no | 0 | Penalizes repeated tokens (-2.0 to 2.0) |
presence_penalty | number | no | 0 | Penalizes tokens based on prior appearance (-2.0 to 2.0) |
stop | string | array | no | | Stop sequences — generation stops when any is encountered |
n | integer | no | 1 | Number of completion choices to generate |
user | string | no | | End-user identifier for abuse monitoring |
| Name | Type | Required | Default | Description |
|---|
role | string | yes | | One of: "system", "user", "assistant", "tool" |
content | string | array | yes | | Message content. Array format supports multimodal (text + image_url) |
name | string | no | | Participant name (optional) |
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?"}
]
}'
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)
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);
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)
}
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(""));
}
}
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"}]
}'
{
"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
}
}
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"}}
]
}
]
}