# Set or remove the price of a model (a person in the browser only; the local token and keys get 403)

> PUT /api/v1/providers/prices: Set or remove the price of a model (a person in the browser only; the local token and keys get 403)

Source: https://stuarty.com/docs/api/providers.prices.set/

## Authentication

Send the secret in the header `Authorization: Bearer <secret>`: the local token in local mode, an [API key](/docs/self-hosting/api-keys) in network mode. An API key needs the `admin` scope; the local token has every scope. See the [API overview](/docs/api/overview) for both modes.

## Request body

Content type `application/json`.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `currency` | `string` | no | Three letters, for example USD; needed to set a price. |
| `input_micros_per_mtok` | `integer (int64)` or `null` | no | The price of a million input tokens, in millionths of the currency unit. Leave both prices out to remove the entry. |
| `model` | `string` | yes | The model id, as provider:models lists it.. min length 1 |
| `output_micros_per_mtok` | `integer (int64)` or `null` | no | The price of a million output tokens, in millionths of the currency unit. |
| `provider` | `string` | yes | The id of the provider, for example openai.. min length 1 |
| `unit` | `string` | no | Empty for a price of tokens, image for the price of one image, mchar for the price of a million characters of speech, second for the price of one second of video. |
| `unit_micros` | `integer (int64)` or `null` | no | With a unit of image, mchar or second: the price of one image, of a million characters or of one second of video, in millionths of the currency unit; the token prices stay out. |

## Responses

### 200 OK

Content type `application/json`. Schema: [`ProviderPricesResult`](/docs/api/schemas#providerpricesresult).

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `prices` | array of [`PriceEntry`](/docs/api/schemas#priceentry) | no |  |

### 400

Validation failed; errors maps each field to its messages and issues lists each problem with its code, key and params

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### 401 Unauthorized

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### 403

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### 429

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### Any other status

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

```bash
curl -X PUT "http://127.0.0.1:7878/api/v1/providers/prices" \
  -H "Authorization: Bearer $STUARTY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "string",
  "provider": "string"
}'
```

```python
import os

import requests

response = requests.put(
    "http://127.0.0.1:7878/api/v1/providers/prices",
    headers={"Authorization": f"Bearer {os.environ['STUARTY_KEY']}"},
    json={
        "model": "string",
        "provider": "string",
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

```javascript
const response = await fetch("http://127.0.0.1:7878/api/v1/providers/prices", {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.STUARTY_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "string",
    "provider": "string"
  }),
});
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
console.log(await response.json());
```

```go
package main

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

func main() {
	body := strings.NewReader(`{
  "model": "string",
  "provider": "string"
}`)
	req, err := http.NewRequest("PUT", "http://127.0.0.1:7878/api/v1/providers/prices", body)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("STUARTY_KEY"))
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	out, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Status, string(out))
}
```

```php
<?php

$ch = curl_init("http://127.0.0.1:7878/api/v1/providers/prices");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "PUT",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("STUARTY_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => '{
  "model": "string",
  "provider": "string"
}',
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new RuntimeException(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $response, PHP_EOL;
```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("http://127.0.0.1:7878/api/v1/providers/prices"))
            .header("Authorization", "Bearer " + System.getenv("STUARTY_KEY"))
            .header("Content-Type", "application/json")
            .method("PUT", HttpRequest.BodyPublishers.ofString("""
                {
                  "model": "string",
                  "provider": "string"
                }
                """))
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}
```

```csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

using var client = new HttpClient();
using var request = new HttpRequestMessage(
    HttpMethod.Put, "http://127.0.0.1:7878/api/v1/providers/prices");
request.Headers.Authorization = new AuthenticationHeaderValue(
    "Bearer", Environment.GetEnvironmentVariable("STUARTY_KEY"));
request.Content = new StringContent("""
{
  "model": "string",
  "provider": "string"
}
""", Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

```ruby
require "net/http"
require "uri"

uri = URI("http://127.0.0.1:7878/api/v1/providers/prices")
request = Net::HTTP::Put.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('STUARTY_KEY')}"
request["Content-Type"] = "application/json"
request.body = '{
  "model": "string",
  "provider": "string"
}'

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end
puts "#{response.code} #{response.body}"
```

**Response examples**

```json
{
  "prices": [
    {
      "currency": "string",
      "input_micros_per_mtok": 0,
      "model": "string",
      "output_micros_per_mtok": 0,
      "provider": "string",
      "unit": "string",
      "unit_micros": 0
    }
  ]
}
```

```json
{
  "code": "string",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "string",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "string",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 0,
  "title": "string",
  "type": "string"
}
```

```json
{
  "code": "E_UNAUTHORIZED",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "send the local token as Authorization: Bearer <token>, or run `stuarty open` to open the editor in a browser",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "the request carries no credentials.",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 401,
  "title": "string",
  "type": "string"
}
```

```json
{
  "code": "string",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "string",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "string",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 0,
  "title": "string",
  "type": "string"
}
```

```json
{
  "code": "string",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "string",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "string",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 0,
  "title": "string",
  "type": "string"
}
```

The examples are built from the schemas of the OpenAPI document, so a value is a placeholder of its type. The fields that carry the real values are in the tables.
