> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runbridge.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Estimate request cost before calling a model

> Estimate RunBridge AI request cost before a model call by combining model directory pricing with input size, output limits, or task count.

Estimate cost before a model call by combining the model directory price with the units that the endpoint bills: tokens or generated images. Treat the estimate as a budget guard, then use actual usage and billing records after the request completes.

## Estimate token-based calls

The following Python example estimates token-based request cost from configured pricing values:

```python theme={null}
import math
import os

prompt = "Write a short product description for RunBridge AI."
max_output_tokens = 200

input_price_per_1m = float(os.environ["MODEL_INPUT_PRICE_PER_1M"])
output_price_per_1m = float(os.environ["MODEL_OUTPUT_PRICE_PER_1M"])

estimated_input_tokens = math.ceil(len(prompt) / 4)

estimated_cost = (
    estimated_input_tokens * input_price_per_1m
    + max_output_tokens * output_price_per_1m
) / 1_000_000

print(f"Estimated maximum cost: ${estimated_cost:.6f}")
```

The result is a pre-call estimate:

```text theme={null}
Estimated maximum cost: $0.000123
```

## Set a maximum output budget

The following request caps generated output so the estimate has an upper bound:

```bash theme={null}
curl https://api.runbridge.ai/v1/chat/completions \
  -H "Authorization: Bearer $RUNBRIDGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "messages": [
      {
        "role": "user",
        "content": "Write a short product description for RunBridge AI."
      }
    ],
    "max_completion_tokens": 200
  }'
```

The response includes actual usage after the model call:

```json theme={null}
{
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 42,
    "total_tokens": 52
  }
}
```

## Estimate task-based calls

For an image model priced per task, the following JavaScript example estimates the cost from the task count:

```javascript theme={null}
const taskCount = 3;
const pricePerTask = Number(process.env.MODEL_PRICE_PER_TASK);

const estimatedCost = taskCount * pricePerTask;

console.log(`Estimated maximum cost: $${estimatedCost.toFixed(4)}`);
```

The result is the task budget:

```text theme={null}
Estimated maximum cost: $0.4500
```

## Common errors

| Error | Fix |
| - | - |
| Using a price from the wrong model | Copy pricing from the same model ID in the model directory. |
| Ignoring output tokens | Set `max_completion_tokens` or the endpoint-specific output limit. |
| Treating estimates as invoices | Compare estimates with actual usage after the call. |
| Using the wrong image billing unit | Check whether the image model is priced by tokens, tasks, or generated images before applying a formula. |

## Related links

* [Pricing](https://runbridge.ai/pricing/)
* [Model directory](https://runbridge.ai/models/)
* [Models page](/overview/models)
* [RunBridge AI pricing](https://runbridge.ai/pricing/)
* [RunBridge AI quickstart](/overview/quick-start)

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "TechArticle",
        "@id": "https://runbridge.mintlify.site/guides/how-to-estimate-cost-before-calling-a-model",
        "headline": "How do I estimate cost before calling a model?",
        "description": "Estimate RunBridge AI request cost before a model call by combining model directory pricing with input size, output limits, or task count.",
        "url": "https://runbridge.mintlify.site/guides/how-to-estimate-cost-before-calling-a-model",
        "author": {
          "@type": "Organization",
          "name": "RunBridge AI"
        },
        "publisher": {
          "@type": "Organization",
          "name": "RunBridge AI",
          "url": "https://runbridge.ai"
        }
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "RunBridge AI Docs",
            "item": "https://runbridge.mintlify.site/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Guides",
            "item": "https://runbridge.mintlify.site/guides/use-runbridge-with-openai-sdk"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "How do I estimate cost before calling a model?",
            "item": "https://runbridge.mintlify.site/guides/how-to-estimate-cost-before-calling-a-model"
          }
        ]
      }
    ]
    }
    `}
</script>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.