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

# Replace model prices

PUT http://localhost:5173/api/v1/private/model-prices
Content-Type: application/json

Replaces the organization's whole list in one go. With dry_run=true it returns what would change and saves nothing

Reference: https://www.comet.com/docs/opik/reference/rest-api/model-prices/replace-model-prices

## Servers

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

## Request

### Query parameters

- `dry_run` (boolean, optional, default: false)

### Body (application/json)

This endpoint expects a CustomModelPriceReplace.

- `rows` (list of JsonNode, required) — The whole list after the change; rows left out are deleted
- `expected_version` (long, optional) — The version the rows were read at; a newer list answers 409 and saves nothing

## Response

### 200

What changed, or would change

- `version` (long, optional)
- `saved` (boolean, optional) — False for a dry run, and when the rows sent match the stored list
- `created` (list of CustomModelPriceRow, optional)
- `updated` (list of CustomModelPriceChange, optional)
- `deleted` (list of CustomModelPriceRow, optional)
- `unchanged` (integer, optional)
- `warnings` (list of Problem, optional)

## Errors

### 403 Forbidden Error

Not an admin of the organization, or the organization is unknown

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

### 409 Conflict Error

The list changed since expected_version

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

### 422 Unprocessable Entity Error

Invalid rows, each problem listed

- `errors` (list of Problem, optional)
- `warnings` (list of Problem, optional)

### 429 Too Many Requests Error

Too many requests

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

### 503 Service Unavailable Error

Custom model prices are disabled

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

## Types

### JsonNode

### CustomModelPriceRow

One of the organization's price rows, in the shape the replace endpoint accepts back

- `id` (string, optional)
- `model` (string, optional)
- `provider` (string, optional) — Empty means any provider
- `kind` (enum, optional)
  - Allowed values: `fixed`, `alias`
- `input_price` (string, optional) — USD per 1M input tokens; absent means the built-in rate
- `output_price` (string, optional) — USD per 1M output tokens; absent means the built-in rate
- `cache_read_price` (string, optional) — USD per 1M cached input tokens read; absent means the built-in rate
- `cache_write_price` (string, optional) — USD per 1M input tokens written to the cache; absent means the built-in rate
- `alias_of` (CustomModelPriceAliasOf, optional)
- `note` (string, optional)
- `created_at` (datetime, optional)
- `created_by` (string, optional)
- `last_updated_at` (datetime, optional)
- `last_updated_by` (string, optional)

### CustomModelPriceChange

- `before` (CustomModelPriceRow, optional) — One of the organization's price rows, in the shape the replace endpoint accepts back
- `after` (CustomModelPriceRow, optional) — One of the organization's price rows, in the shape the replace endpoint accepts back

### Problem

- `row` (integer, optional)
- `field` (string, optional)
- `code` (enum, optional)
  - Allowed values: `too_many_rows`, `not_an_object`, `unknown_field`, `not_a_string`, `not_a_number`, `missing_model`, `name_too_long`, `control_characters`, `missing_kind`, `unknown_kind`, `note_too_long`, `no_price`, `field_not_for_kind`, `missing_alias_target`, `too_many_decimals`, `price_too_high`, `cache_price_not_positive`, `negative_price`, `duplicate_row`, `alias_target_is_itself`, `alias_target_is_alias`, `alias_target_unpriced`, `name_normalized`, `provider_unpriced`, `shadows_builtin`, `no_base`, `priced_per_unit`, `price_out_of_range`
- `message` (string, optional)

### CustomModelPriceAliasOf

- `model` (string, optional)
- `provider` (string, optional) — Empty means the span's own provider

## Examples

**Request**

```json
{
  "rows": [
    {}
  ]
}
```

**Response**

```json
{
  "version": 1,
  "saved": true,
  "created": [
    {
      "id": "string",
      "model": "string",
      "provider": "string",
      "kind": "fixed",
      "input_price": "1.25",
      "output_price": "10",
      "cache_read_price": "string",
      "cache_write_price": "string",
      "alias_of": {
        "model": "string",
        "provider": "string"
      },
      "note": "string",
      "created_at": "2024-01-15T09:30:00Z",
      "created_by": "string",
      "last_updated_at": "2024-01-15T09:30:00Z",
      "last_updated_by": "string"
    }
  ],
  "updated": [
    {
      "before": {
        "id": "string",
        "model": "string",
        "provider": "string",
        "kind": "fixed",
        "input_price": "1.25",
        "output_price": "10",
        "cache_read_price": "string",
        "cache_write_price": "string",
        "alias_of": {
          "model": "string",
          "provider": "string"
        },
        "note": "string",
        "created_at": "2024-01-15T09:30:00Z",
        "created_by": "string",
        "last_updated_at": "2024-01-15T09:30:00Z",
        "last_updated_by": "string"
      },
      "after": {
        "id": "string",
        "model": "string",
        "provider": "string",
        "kind": "fixed",
        "input_price": "1.25",
        "output_price": "10",
        "cache_read_price": "string",
        "cache_write_price": "string",
        "alias_of": {
          "model": "string",
          "provider": "string"
        },
        "note": "string",
        "created_at": "2024-01-15T09:30:00Z",
        "created_by": "string",
        "last_updated_at": "2024-01-15T09:30:00Z",
        "last_updated_by": "string"
      }
    }
  ],
  "deleted": [
    {
      "id": "string",
      "model": "string",
      "provider": "string",
      "kind": "fixed",
      "input_price": "1.25",
      "output_price": "10",
      "cache_read_price": "string",
      "cache_write_price": "string",
      "alias_of": {
        "model": "string",
        "provider": "string"
      },
      "note": "string",
      "created_at": "2024-01-15T09:30:00Z",
      "created_by": "string",
      "last_updated_at": "2024-01-15T09:30:00Z",
      "last_updated_by": "string"
    }
  ],
  "unchanged": 1,
  "warnings": [
    {
      "row": 1,
      "field": "string",
      "code": "too_many_rows",
      "message": "string"
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "http://localhost:5173/api/v1/private/model-prices"

payload = { "rows": [{}] }
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/model-prices';
const options = {
  method: 'PUT',
  headers: {'Content-Type': 'application/json'},
  body: '{"rows":[{}]}'
};

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/model-prices"

	payload := strings.NewReader("{\n  \"rows\": [\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/model-prices")

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

request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"rows\": [\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/model-prices")
  .header("Content-Type", "application/json")
  .body("{\n  \"rows\": [\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/model-prices', [
  'body' => '{
  "rows": [
    {}
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

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

```swift
import Foundation

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

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

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