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

# Create chat completions

POST http://localhost:5173/api/v1/private/chat/completions
Content-Type: application/json

Create chat completions

Reference: https://www.comet.com/docs/opik/reference/rest-api/chat-completions/create-chat-completions

## Servers

- `http://localhost:5173/api` (Local server, default)
- `https://www.comet.com/opik/api` (Opik Cloud)

## Request

### Body (application/json)

This endpoint expects a ChatCompletionRequest.

- `model` (string, optional)
- `messages` (list of Message, optional)
- `temperature` (double, optional)
- `topP` (double, optional)
- `n` (integer, optional)
- `stream` (boolean, optional)
- `streamOptions` (StreamOptions, optional)
- `stop` (list of string, optional)
- `maxTokens` (integer, optional)
- `maxCompletionTokens` (integer, optional)
- `presencePenalty` (double, optional)
- `frequencyPenalty` (double, optional)
- `logitBias` (map from string to integer, optional)
- `user` (string, optional)
- `responseFormat` (ResponseFormat, optional)
- `seed` (integer, optional)
- `tools` (list of Tool, optional)
- `toolChoice` (ChatCompletionRequestToolChoice, optional)
- `parallelToolCalls` (boolean, optional)
- `store` (boolean, optional)
- `metadata` (map from string to string, optional)
- `reasoningEffort` (string, optional)
- `serviceTier` (string, optional)
- `logprobs` (boolean, optional)
- `topLogprobs` (integer, optional)
- `functions` (list of Function, optional)
- `functionCall` (FunctionCall, optional)

## Response

### 200

Chat completions response

- `id` (string, optional)
- `created` (long, optional)
- `model` (string, optional)
- `choices` (list of ChatCompletionChoice, optional)
- `usage` (Usage, optional)
- `systemFingerprint` (string, optional)
- `serviceTier` (string, optional)

## Types

### Message

- `role` (string, required)
- `content` (JsonNode, required)

### StreamOptions

- `includeUsage` (boolean, optional)

### ResponseFormat

- `type` (enum, optional)
  - Allowed values: `text`, `json_object`, `json_schema`
- `jsonSchema` (JsonSchema, optional)

### Tool

- `type` (enum, optional)
  - Allowed values: `function`
- `function` (Function, optional)

### ChatCompletionRequestToolChoice

### Function

- `name` (string, optional)
- `description` (string, optional)
- `strict` (boolean, optional)
- `parameters` (map from string to FunctionParameters, optional)

### FunctionCall

- `name` (string, optional)
- `arguments` (string, optional)

### ChatCompletionChoice

- `index` (integer, optional)
- `message` (AssistantMessage, optional)
- `delta` (Delta, optional)
- `finishReason` (string, optional)
- `logprobs` (LogProbs, optional)

### Usage

- `totalTokens` (integer, optional)
- `promptTokens` (integer, optional)
- `promptTokensDetails` (PromptTokensDetails, optional)
- `completionTokens` (integer, optional)
- `completionTokensDetails` (CompletionTokensDetails, optional)

### JsonNode

### JsonSchema

- `name` (string, optional)
- `strict` (boolean, optional)
- `schema` (map from string to JsonSchemaSchema, optional)

### FunctionParameters

### AssistantMessage

- `role` (enum, optional)
  - Allowed values: `system`, `user`, `assistant`, `tool`, `function`
- `content` (string, optional)
- `reasoningContent` (string, optional)
- `name` (string, optional)
- `toolCalls` (list of ToolCall, optional)
- `refusal` (string, optional)
- `functionCall` (FunctionCall, optional)

### Delta

- `role` (string, optional)
- `content` (string, optional)
- `reasoningContent` (string, optional)
- `toolCalls` (list of ToolCall, optional)
- `functionCall` (FunctionCall, optional)

### LogProbs

- `content` (list of LogProb, optional)

### PromptTokensDetails

- `cachedTokens` (integer, optional)

### CompletionTokensDetails

- `reasoningTokens` (integer, optional)

### JsonSchemaSchema

### ToolCall

- `id` (string, optional)
- `index` (integer, optional)
- `type` (enum, optional)
  - Allowed values: `function`
- `function` (FunctionCall, optional)

### LogProb

- `token` (string, optional)
- `logprob` (double, optional)
- `bytes` (list of integer, optional)

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "id": "string",
  "created": 1,
  "model": "string",
  "choices": [
    {
      "index": 1,
      "message": {
        "role": "system",
        "content": "string",
        "reasoningContent": "string",
        "name": "string",
        "toolCalls": [
          {
            "id": "string",
            "index": 1,
            "type": "function",
            "function": {
              "name": "string",
              "arguments": "string"
            }
          }
        ],
        "refusal": "string",
        "functionCall": {
          "name": "string",
          "arguments": "string"
        }
      },
      "delta": {
        "role": "string",
        "content": "string",
        "reasoningContent": "string",
        "toolCalls": [
          {
            "id": "string",
            "index": 1,
            "type": "function",
            "function": {
              "name": "string",
              "arguments": "string"
            }
          }
        ],
        "functionCall": {
          "name": "string",
          "arguments": "string"
        }
      },
      "finishReason": "string",
      "logprobs": {
        "content": [
          {
            "token": "string",
            "logprob": 1.1,
            "bytes": [
              1
            ]
          }
        ]
      }
    }
  ],
  "usage": {
    "totalTokens": 1,
    "promptTokens": 1,
    "promptTokensDetails": {
      "cachedTokens": 1
    },
    "completionTokens": 1,
    "completionTokensDetails": {
      "reasoningTokens": 1
    }
  },
  "systemFingerprint": "string",
  "serviceTier": "string"
}
```

**SDK Code**

```python
import requests

url = "http://localhost:5173/api/v1/private/chat/completions"

payload = {}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'http://localhost:5173/api/v1/private/chat/completions';
const options = {method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{}'};

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

```go
package main

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

func main() {

	url := "http://localhost:5173/api/v1/private/chat/completions"

	payload := strings.NewReader("{}")

	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
require 'uri'
require 'net/http'

url = URI("http://localhost:5173/api/v1/private/chat/completions")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{}"

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

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

HttpResponse<String> response = Unirest.post("http://localhost:5173/api/v1/private/chat/completions")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:5173/api/v1/private/chat/completions', [
  'body' => '{}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("http://localhost:5173/api/v1/private/chat/completions");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:5173/api/v1/private/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()
```