DEV Community

EdsonFernando
EdsonFernando

Posted on

How We Reduced the Cost of Accessing AI Models by Up to 80%

While developing CodeAPI, we noticed that the official price of an AI API does not always represent the lowest possible cost for accessing a particular model.

This applies to both open-source and proprietary models. Depending on the source, volume, and purchasing terms, the same model can be available at significantly different prices.

That led us to build an infrastructure that looks for more competitive sources for each model and makes them available through a single API.

The goal is not to create new models or modify existing ones. CodeAPI is an access layer for models from different providers, with a unified interface for consuming them.

One of the things we simplified was pricing.

With CodeAPI, the price per million tokens is the same for input and output tokens. Users do not need to work with two separate pricing tables:

1 million input tokens = the same rate
1 million output tokens = the same rate

For example, if a particular route costs US$0.10 per million tokens:

5 million input tokens = US$0.50
5 million output tokens = US$0.50

On some routes, this structure allows us to reduce the cost by up to 80% compared with the official reference price.

Reference price CodeAPI price Reduction
US$0.50/M tokens US$0.10/M tokens 80%
US$1.00/M tokens US$0.20/M tokens 80%
US$2.00/M tokens US$0.40/M tokens 80%

For a total consumption of 100 million tokens:

Reference price: US$100
CodeAPI: US$20
Difference: US$80

These values illustrate the difference in proportion. The actual price depends on the model, the available source, and the route being used. The reduction is not necessarily the same for every model.

The infrastructure supports both open-source and proprietary models. Since the API follows an OpenAI-compatible format, it can be used with applications and tools that already support this standard.

We have also been able to use it with clients such as Claude Code, while keeping the same general access and usage-based billing model.

A basic integration using the OpenAI SDK looks like this:

python

from openai import OpenAI

client = OpenAI(
    base_url="https://api.codeapi.pro/v1",
    api_key="YOUR_API_KEY"
)

response = client.chat.completions.create(
    model="model-name",
    messages=[
        {
            "role": "user",
            "content": "Hello"
        }
    ]
)

print(response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

For projects that already use this standard, integration generally involves changing the base_url, API key, and model name.

We are still evaluating differences in latency, availability, and rate limits between sources. These factors also matter in production environments; price alone does not determine the best route.

CodeAPI came out of this effort to find more competitive sources for both open-source and proprietary models, while providing a single and more predictable way to use them.

More information and API access:

codeapi

Feedback from people already using AI models in production would be especially useful, particularly regarding token volume, cost, latency, and compatibility with tools such as Claude Code.

Top comments (0)