> 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.

# Record experiment items in bulk

PUT http://localhost:5173/api/v1/private/experiments/items/bulk
Content-Type: application/json

Record experiment items in bulk with traces, spans, and feedback scores. Maximum request size is 4MB.

Reference: https://www.comet.com/docs/opik/reference/rest-api/experiments/experiment-items-bulk

## Servers

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

## Request

### Body (application/json)

This endpoint expects an ExperimentItemBulkUpload_ExperimentItemBulkWriteView.

- `experiment_name` (string, required)
- `dataset_name` (string, required)
- `items` (list of ExperimentItemBulkRecord_ExperimentItemBulkWriteView, required)
- `experiment_id` (string, optional) — Optional experiment ID. If provided, items will be added to the existing experiment and experimentName will be ignored. If not provided or experiment with that ID doesn't exist, a new experiment will be created with the given experimentName
- `project_name` (string, optional) — Project for traces auto-created from items that provide evaluate_task_result (i.e. without an explicit trace). If null, the default project is used; relying on this fallback is deprecated, please provide project_name explicitly.

## Response

### 204

No content

## Errors

### 400 Bad Request Error

Bad Request

- `code` (integer, optional)
- `message` (string, optional)
- `details` (string, optional)

### 409 Conflict Error

Conflict

- `code` (integer, optional)
- `message` (string, optional)
- `details` (string, optional)

### 422 Unprocessable Entity Error

Unprocessable Content

- `code` (integer, optional)
- `message` (string, optional)
- `details` (string, optional)

## Types

### ExperimentItemBulkRecord_ExperimentItemBulkWriteView

- `dataset_item_id` (string, required)
- `evaluate_task_result` (JsonListString_ExperimentItemBulkWriteView, optional)
- `trace` (Trace_ExperimentItemBulkWriteView, optional) — Please provide either none, only one of evaluate_task_result or trace, but never both
- `spans` (list of Span_ExperimentItemBulkWriteView, optional)
- `feedback_scores` (list of FeedbackScore_ExperimentItemBulkWriteView, optional)

### JsonListString_ExperimentItemBulkWriteView

### Trace_ExperimentItemBulkWriteView

Please provide either none, only one of evaluate_task_result or trace, but never both

- `start_time` (datetime, required)
- `id` (string, optional)
- `project_name` (string, optional) — If null, the default project is used
- `name` (string, optional)
- `end_time` (datetime, optional)
- `input` (JsonListString_ExperimentItemBulkWriteView, optional)
- `output` (JsonListString_ExperimentItemBulkWriteView, optional)
- `metadata` (JsonListString_ExperimentItemBulkWriteView, optional)
- `tags` (list of string, optional)
- `error_info` (ErrorInfo_ExperimentItemBulkWriteView, optional)
- `last_updated_at` (datetime, optional)
- `ttft` (double, optional) — Time to first token in milliseconds
- `thread_id` (string, optional)
- `source` (enum, optional)
  - Allowed values: `sdk`, `experiment`, `playground`, `optimization`, `evaluator`
- `environment` (string, optional)

### Span_ExperimentItemBulkWriteView

- `start_time` (datetime, required)
- `id` (string, optional)
- `parent_span_id` (string, optional)
- `name` (string, optional)
- `type` (enum, optional)
  - Allowed values: `general`, `tool`, `llm`, `guardrail`
- `end_time` (datetime, optional)
- `input` (JsonListString_ExperimentItemBulkWriteView, optional)
- `output` (JsonListString_ExperimentItemBulkWriteView, optional)
- `metadata` (JsonListString_ExperimentItemBulkWriteView, optional)
- `model` (string, optional)
- `provider` (string, optional)
- `tags` (list of string, optional)
- `usage` (map from string to integer, optional)
- `error_info` (ErrorInfo_ExperimentItemBulkWriteView, optional)
- `last_updated_at` (datetime, optional)
- `total_estimated_cost` (double, optional)
- `total_estimated_cost_version` (string, optional)
- `ttft` (double, optional) — Time to first token in milliseconds
- `source` (enum, optional)
  - Allowed values: `sdk`, `experiment`, `playground`, `optimization`, `evaluator`
- `environment` (string, optional)

### FeedbackScore_ExperimentItemBulkWriteView

- `name` (string, required)
- `value` (double, required)
- `source` (enum, required)
  - Allowed values: `ui`, `sdk`, `online_scoring`
- `category_name` (string, optional)
- `reason` (string, optional)
- `source_queue_id` (string, optional)
- `created_at` (datetime, optional)
- `last_updated_at` (datetime, optional)
- `created_by` (string, optional)
- `last_updated_by` (string, optional)
- `value_by_author` (map from string to ValueEntry_ExperimentItemBulkWriteView, optional)

### ErrorInfo_ExperimentItemBulkWriteView

- `exception_type` (string, required)
- `traceback` (string, required)
- `message` (string, optional)

### ValueEntry_ExperimentItemBulkWriteView

- `value` (double, optional)
- `reason` (string, optional)
- `category_name` (string, optional)
- `source` (enum, optional)
  - Allowed values: `ui`, `sdk`, `online_scoring`
- `last_updated_at` (datetime, optional)
- `span_type` (string, optional)
- `span_id` (string, optional)
- `source_queue_id` (string, optional)
- `author` (string, optional)

## Examples

**Request**

```json
{
  "experiment_name": "string",
  "dataset_name": "string",
  "items": [
    {
      "dataset_item_id": "string"
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "http://localhost:5173/api/v1/private/experiments/items/bulk"

payload = {
    "experiment_name": "string",
    "dataset_name": "string",
    "items": [{ "dataset_item_id": "string" }]
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'http://localhost:5173/api/v1/private/experiments/items/bulk';
const options = {
  method: 'PUT',
  headers: {'Content-Type': 'application/json'},
  body: '{"experiment_name":"string","dataset_name":"string","items":[{"dataset_item_id":"string"}]}'
};

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/experiments/items/bulk"

	payload := strings.NewReader("{\n  \"experiment_name\": \"string\",\n  \"dataset_name\": \"string\",\n  \"items\": [\n    {\n      \"dataset_item_id\": \"string\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("PUT", 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/experiments/items/bulk")

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

request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"experiment_name\": \"string\",\n  \"dataset_name\": \"string\",\n  \"items\": [\n    {\n      \"dataset_item_id\": \"string\"\n    }\n  ]\n}"

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.put("http://localhost:5173/api/v1/private/experiments/items/bulk")
  .header("Content-Type", "application/json")
  .body("{\n  \"experiment_name\": \"string\",\n  \"dataset_name\": \"string\",\n  \"items\": [\n    {\n      \"dataset_item_id\": \"string\"\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'http://localhost:5173/api/v1/private/experiments/items/bulk', [
  'body' => '{
  "experiment_name": "string",
  "dataset_name": "string",
  "items": [
    {
      "dataset_item_id": "string"
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("http://localhost:5173/api/v1/private/experiments/items/bulk");
var request = new RestRequest(Method.PUT);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"experiment_name\": \"string\",\n  \"dataset_name\": \"string\",\n  \"items\": [\n    {\n      \"dataset_item_id\": \"string\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "experiment_name": "string",
  "dataset_name": "string",
  "items": [["dataset_item_id": "string"]]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:5173/api/v1/private/experiments/items/bulk")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```