> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/local-ai/nvpair/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/local-ai/nvpair/_mcp/server.

# OpenAI-compatible chat completion

POST http%3A%2F%2F127.0.0.1%3A11434/v1/chat/completions
Content-Type: application/json

Send an OpenAI-compatible chat completion request to the local PAIR proxy. PAIR forwards the entire request to a single eligible node and returns the engine's response.


Reference: https://docs.nvidia.com/local-ai/nvpair/pair-api/open-ai-compatible/create-chat-completion

## Request

### Body (application/json)

This endpoint expects a ChatCompletionRequest.

- `model` (string, required) — Model name that must be available on an eligible node.
- `messages` (list of ChatMessage, required)
- `stream` (boolean, optional, default: false)
- `temperature` (float, optional)
- `max_tokens` (integer, optional)

## Response

### 200

Chat completion from the serving node.

- `id` (string, required)
- `object` (string, required)
- `created` (long, required) — Unix timestamp in seconds.
- `model` (string, required)
- `choices` (list of ChatCompletionChoice, required)
- `usage` (Usage, optional)

## Types

### ChatMessage

- `role` (enum, required)
  - Allowed values: `system`, `user`, `assistant`, `tool`
- `content` (string, required)

### ChatCompletionChoice

- `index` (integer, required)
- `message` (ChatMessage, required)
- `finish_reason` (enum, optional)
  - Allowed values: `stop`, `length`, `tool_calls`, `content_filter`

### Usage

- `prompt_tokens` (integer, optional)
- `completion_tokens` (integer, optional)
- `total_tokens` (integer, optional)

## Examples

**Request**

```json
{
  "model": "llama3.1",
  "messages": [
    {
      "role": "user",
      "content": "Explain what NVIDIA Personal AI Router does in one sentence."
    }
  ]
}
```

**Response**

```json
{
  "id": "chatcmpl-01J0D5P0KZESQHTR2HWK7S5W27",
  "object": "chat.completion",
  "created": 1780000000,
  "model": "llama3.1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "NVIDIA Personal AI Router routes each AI request to one eligible system on your local network to serve inference."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 18,
    "completion_tokens": 24,
    "total_tokens": 42
  }
}
```

**SDK Code**

```python default
import requests

url = "https://api.example.com/v1/chat/completions"

payload = {
    "model": "llama3.1",
    "messages": [
        {
            "role": "user",
            "content": "Explain what NVIDIA Personal AI Router does in one sentence."
        }
    ]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript default
const url = 'https://api.example.com/v1/chat/completions';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"model":"llama3.1","messages":[{"role":"user","content":"Explain what NVIDIA Personal AI Router does in one sentence."}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go default
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/chat/completions"

	payload := strings.NewReader("{\n  \"model\": \"llama3.1\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Explain what NVIDIA Personal AI Router does in one sentence.\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby default
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/chat/completions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"llama3.1\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Explain what NVIDIA Personal AI Router does in one sentence.\"\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java default
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/chat/completions")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"llama3.1\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Explain what NVIDIA Personal AI Router does in one sentence.\"\n    }\n  ]\n}")
  .asString();
```

```php default
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/chat/completions', [
  'body' => '{
  "model": "llama3.1",
  "messages": [
    {
      "role": "user",
      "content": "Explain what NVIDIA Personal AI Router does in one sentence."
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp default
using RestSharp;

var client = new RestClient("https://api.example.com/v1/chat/completions");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"llama3.1\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Explain what NVIDIA Personal AI Router does in one sentence.\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift default
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "model": "llama3.1",
  "messages": [
    [
      "role": "user",
      "content": "Explain what NVIDIA Personal AI Router does in one sentence."
    ]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/chat/completions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```