Launch Week 3: Five days of launches

Model Costs

Overview

The Confident AI SDK exposes every Model Cost method on the platform. This page documents how to call these methods in all supported languages. See the introduction to install the SDK and set your API key.

Methods

List Model Costs

Lists the custom model prices your Confident AI project uses one page at a time, newest first. When the project inherits its pricing from the organization the response carries the organization's model costs and inherit is true, in which case they can only be changed from the organization's own project.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.model_costs.list(page=1, page_size=25, search_term="gpt-4o")

For async mode, call a_list and await it as shown below:

result = await client.model_costs.a_list(...)

Parameters

ParameterTypeDescription
pageOptional[int]The page to return. Defaults to 1.
page_sizeOptional[int]The number of model costs per page, at most 100. Defaults to 25.
search_termOptional[str]Returns only model costs whose match pattern or provider contains this text, case-insensitively.

Returns

This method returns an object of type ModelCostList.

Create Model Cost

Adds a custom model price to your Confident AI project and returns its id. Confident AI applies it to an LLM span whose model name matches matchPattern and whose provider did not report a priceable cost. This fails while the project inherits its model costs from the organization.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.model_costs.create(
    match_pattern="^gpt-4o",
    provider="openai",
    input_cost_per_million_tokens=2.5,
    output_cost_per_million_tokens=10,
)

For async mode, call a_create and await it as shown below:

result = await client.model_costs.a_create(...)

Parameters

ParameterTypeDescription
match_patternstrRequired. The case-insensitive regular expression a model name must match for this cost to apply.
providerOptional[str]The model provider this cost applies to, matched case- insensitively against the provider recorded on the LLM span. Send null or omit it for a cost that applies whatever the provider, which is only used when no provider-specific cost matches.
input_cost_per_million_tokensOptional[float]The cost in USD of one million input tokens. Send null when only the output rate is priced; input tokens are then costed at zero.
output_cost_per_million_tokensOptional[float]The cost in USD of one million output tokens. Send null when only the input rate is priced; output tokens are then costed at zero.

Returns

This method returns an object of type ModelCostRef.

Update Model Cost

Replaces a custom model price and returns it. The body is the model cost as it should read afterwards, so a field you omit is cleared rather than left alone. This fails while the project inherits its model costs from the organization.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.model_costs.update(
    model_cost_id="<MODEL-COST-ID>",
    match_pattern="^gpt-4o",
    provider="openai",
    input_cost_per_million_tokens=2.5,
    output_cost_per_million_tokens=10,
)

For async mode, call a_update and await it as shown below:

result = await client.model_costs.a_update(...)

Parameters

ParameterTypeDescription
model_cost_idstrRequired. The id of the model cost.
match_patternstrRequired. The case-insensitive regular expression a model name must match for this cost to apply.
providerOptional[str]The model provider this cost applies to, matched case- insensitively against the provider recorded on the LLM span. Send null or omit it for a cost that applies whatever the provider, which is only used when no provider-specific cost matches.
input_cost_per_million_tokensOptional[float]The cost in USD of one million input tokens. Send null when only the output rate is priced; input tokens are then costed at zero.
output_cost_per_million_tokensOptional[float]The cost in USD of one million output tokens. Send null when only the input rate is priced; output tokens are then costed at zero.

Returns

This method returns an object of type ModelCost.

Delete Model Cost

Permanently deletes a custom model price. Models it matched fall back to Confident AI's own pricing, and costs already recorded on past spans are unchanged. This fails while the project inherits its model costs from the organization.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.model_costs.delete(model_cost_id="<MODEL-COST-ID>")

For async mode, call a_delete and await it as shown below:

result = await client.model_costs.a_delete(...)

Parameters

ParameterTypeDescription
model_cost_idstrRequired. The id of the model cost.

Returns

This method returns an object of type ModelCostRef.

Types

ModelCost

A custom price for the models whose names match matchPattern. Confident AI uses it to cost an LLM span whose provider did not report a priceable cost, taking a provider-specific match first and a provider-less one otherwise.

class ModelCost:
    id: str
    match_pattern: str = Field(alias="matchPattern")
    provider: Optional[str]
    input_cost_per_million_tokens: Optional[float] = Field(alias="inputCostPerMillionTokens")
    output_cost_per_million_tokens: Optional[float] = Field(alias="outputCostPerMillionTokens")
    created_at: str = Field(alias="createdAt")
    updated_at: str = Field(alias="updatedAt")

idstrRequired

The id of the model cost, generated by Confident AI.

Example: "<MODEL-COST-ID>"

match_patternstrRequired

The case-insensitive regular expression a model name must match for this cost to apply.

Example: "^gpt-4o"

providerOptional[str]Required

The model provider this cost applies to, or null when it applies whatever the provider.

Example: "openai"

input_cost_per_million_tokensOptional[float]Required

The cost in USD of one million input tokens, or null when the input rate is not priced.

Example: 2.5

output_cost_per_million_tokensOptional[float]Required

The cost in USD of one million output tokens, or null when the output rate is not priced.

Example: 10

created_atstrRequired

The timestamp when the model cost was created.

Example: "2025-01-15T10:30:00+00:00"

updated_atstrRequired

The timestamp when the model cost was last updated.

Example: "2025-01-16T09:05:00+00:00"

ModelCostList

One page of model costs, with the total across all pages.

class ModelCostList:
    model_costs: List[ModelCost] = Field(alias="modelCosts")
    total_model_costs: int = Field(alias="totalModelCosts")
    inherit: bool
    page: int
    page_size: int = Field(alias="pageSize")

model_costsList[ModelCost]Required

The model costs for the current page, newest first.

See ModelCost.

total_model_costsintRequired

The total number of model costs this project resolves.

Example: 4

inheritboolRequired

Whether these model costs come from the organization rather than the project. When true they are read-only through the API, and creating, updating or deleting one fails until 'Inherit Custom Model Pricing From Organization' is turned off in the project's model costs settings.

Example: false

pageintRequired

The page this response covers.

Example: 1

page_sizeintRequired

The number of model costs per page.

Example: 25

ModelCostRef

A reference to a model cost by its id.

class ModelCostRef:
    id: str

idstrRequired

The id of the model cost, generated by Confident AI.

Example: "<MODEL-COST-ID>"

Building a production pipeline?Design a scalable API workflow for evals, datasets, traces, and promptsTalk to an engineer

Last updated on

Built byConfident AI