Tovanix
Tovanix

Using the AI API Gateway

Call models from multiple providers with one API key, billed from your account balance by actual usage:

  • Create keys under AI Services → API Gateway → API Keys, choose a pricing group for each provider, and optionally set a monthly spend cap, which you can change later in the key list
  • The OpenAI, Anthropic and Gemini request formats are supported; integrating usually only means changing the gateway address and the key
  • Price = official price × pricing group ratio, and some groups have off-peak pricing
  • An amount is reserved before each call and settled at actual usage afterwards, with charges deducted from your balance in one combined charge every minute
  • Usage & Logs provides statistics and per-call detail

What the gateway is for

The API gateway in AI Services is a single entry point for calling large language models: one API key calls models from multiple providers, usage is billed from your account balance as you go, and there is no need to open an account and prepay with each provider separately.

  • Official SDKs work as they are: integration usually means changing base_url and api_key and nothing else, with request and response structures unchanged.
  • Three request formats are supported — OpenAI, Anthropic and Gemini — and you can call across formats, for example calling a Claude model with the OpenAI SDK; the gateway converts automatically.
  • Pricing is by pricing group: within a group, each model has a single price. When a group has several routes and one fails, the request automatically moves to the next route in the same group, at the same price.

Creating an API key

  • Open the API keys page: In the console, go to AI Services → API Gateway → API Keys and click "Create Key" in the top right.
  • Set a name, pricing groups and a monthly cap: Name it after its purpose, for example production, test or cursor. For each provider that offers more than one group, choose a "Pricing group"; if you do not, that provider's default group is used. Leaving the monthly spend cap empty means no limit, while entering 0 allows no spending this month; you can change the cap later by clicking "Change limit" in the key list, which requires identity verification.
  • Verify your identity: After you click "Create", you need to verify your identity: with two-factor authentication (2FA) on, enter the 6-digit code from your authenticator; without it, enter the code sent to your email. Once verified, creating more keys or changing a cap within 10 minutes in the same session does not require verifying again.
  • Save the plaintext key immediately: The key looks like sk-nc- followed by a string and is shown only once, because the backend stores only its hash. Copy it into your password manager before closing the dialog.

Once that dialog closes the plaintext is gone for good — the platform holds a hash, not the key. If you did not save it, the only option is to delete the key and create another. Deleting takes effect immediately and anything still using that key will disconnect.

Pricing groups

A pricing group decides the price at which this key is billed when it calls a given provider's models: price = official price × group ratio. Groups are organized by provider, and each provider has its own groups plus a default group.

  • When creating a key, you only need to choose for providers with two or more groups; providers with a single group need no choice. Any provider you leave unselected uses its default group.
  • The "Group" column in the key list shows the group and ratio chosen for each provider; click "Change" to switch, and the new group's pricing applies from the next call.
  • Calls only use routes in the chosen group and never switch to another group, so a model's price does not change because the route changed.

If the group chosen for a provider is disabled, the list shows "Group disabled", and calls to that provider's models with this key are refused (HTTP 403). Click "Change" to pick another group.

Making your first call

The gateway address is the domain the console runs on. The Dashboard page has curl examples in the OpenAI, Anthropic and Gemini formats, and the dialog shown after a key is created has one too, all with the gateway address already filled in.

  • OpenAI — /v1/chat/completions — Authorization header, with the value Bearer followed by your key
  • Anthropic — /v1/messages — x-api-key header
  • Gemini — /v1beta/models/model-name:generateContent; for streaming, use :streamGenerateContent — x-goog-api-key header, or the ?key= URL parameter
  • With an official SDK, point base_url at the gateway and set api_key to this key; the rest of your code stays as it is.
  • There are also /v1/models (lists available models), /v1/embeddings (text embeddings) and /v1/images/generations (image generation, billed per image), all called in the OpenAI format.
  • Set model in the request to the model ID shown on the card in the Model Marketplace. A wrong ID, or a model that is not listed, returns 404.

The model marketplace and how prices are shown

The model marketplace lists every available model by provider and can be searched by name, slug, description or capability, showing context length, maximum output and other parameters alongside.

  • Price = official price × pricing group ratio. The "All" tab shows each provider's default group; open a provider to switch between its groups. The multiplier in the top-right corner of a card is the current group's ratio.
  • Models priced by token show input and output separately, per 1 million tokens, and a cache-read price, where there is one, gets its own line. Models priced per image, second, minute or call — such as image, audio and video models — show the unit price directly on the card.
  • Some model cards have a "Prompts over" line with a price for a certain length: when a request's prompt exceeds that length, the whole request is billed at that line's price.
  • For models whose card has a "Web search" line, using the model's built-in web search is billed separately by the number of searches.

When a group has off-peak pricing, the card shows "Off-peak" with the ratio, and hovering over it shows the peak hours; outside peak hours the group price is multiplied by that ratio, based on when the request is made. When a card says "No route in this group yet", it lists the groups that can use the model; "Unavailable" means no group can call it at the moment.

Usage and logs

The top half of AI Services → API Gateway → Usage & Logs shows statistics, switchable between 24 hours, 7 days, 30 days and 90 days (7 days by default); the bottom half is the per-call detail.

  • Statistics: requests, amount billed, total tokens (including cached tokens), success rate and average latency, plus a daily trend and rankings by model and by key.
  • Detail: for each call, the time, model, whether it streamed, input / output / cache tokens, amount billed, ratio, latency and status, filterable by model slug.
  • The detail only records calls that reached a model, with the status "Success" or "Error"; "Error" records are not billed. Requests refused before reaching a model (for example an invalid key, a monthly cap already reached, insufficient balance or a disabled group) do not appear in the detail; see the error message returned by the API for the reason.
  • The "Ratio" column shows the group ratio and does not include off-peak discounts; what each call actually costs is in the "Billed USD" column.

How you are billed

Usage is billed from your account balance as you go; there is nothing to fund separately for this service. The cost of each call = official price × group ratio; for groups with off-peak hours, it is further multiplied by the off-peak ratio during those hours, based on when the request is made.

  • Before a call, an amount is reserved based on the input length and the model's maximum output; after the call it is settled at actual usage and the rest is released. If your available balance cannot cover the reservation, the call returns insufficient balance (HTTP 402), and the error message states how much needs to be reserved and how much is currently available.
  • Costs accumulate call by call and are deducted from your balance in one combined charge every minute; the bills under Finance get one "AI Services usage (1-hour summary)" entry each hour.
  • When your available balance drops to $5 or less, the platform reminds you once through on-site messages and other notification channels; if it goes back above $5 and drops again, you are reminded again. During this time, API responses carry the headers X-Tovanix-Balance-Low: 1 and X-Tovanix-Balance-Available (the amount currently available), so your program can prompt a top-up in advance.
  • Each key can have its own monthly spend cap, counted by calendar month and reset automatically at the start of the next month. It is checked before each call: once this month's spending plus calls in progress reaches the cap, no more calls are let through; the last call is settled at actual usage, so a month's spending can slightly exceed the cap.

Cautions

  • The plaintext key appears only at creation — save it then and there.
  • Deleting a key takes effect immediately and cannot be undone. If you only want to pause it, click "Disable" in the list; you can click "Enable" later.
  • A monthly cap of 0 blocks that key entirely for the month; do not use 0 to mean unlimited.
  • The gateway processes requests at the standard tier: a speed tier specified in the request (such as Claude's speed: fast or OpenAI's service_tier) is ignored, and the cost is calculated at the standard price.
  • When you call in the Anthropic format with the web search tool and the request sets no limit on the number of searches, each request performs at most 10 searches.

Troubleshooting

  • 401 returned, saying the key is invalid or disabled — The key is wrong, has been deleted or is disabled — On the API Keys page, confirm the key is "Enabled"; if it is disabled, click "Enable". A deleted key cannot be recovered, so create a new one.
  • 402 returned, saying the monthly spend cap has been reached — This key's spending this month has reached its cap (a cap of 0 allows no spending this month) — It resets automatically next month. If you cannot wait, click "Change limit" for the key on the API Keys page and raise the cap or leave it empty for no limit (identity verification required); the new cap applies from the next call.
  • 402 returned, saying the balance is insufficient — Your available balance cannot cover the amount reserved for this request — The error message states the amount to be reserved and the amount currently available; top up and try again.
  • 403 or 503 returned, saying the group is disabled or no route is available — The group chosen on the key for this provider is disabled, or the group temporarily has no available route for this model — Click "Change" on the API Keys page to switch groups; the model's card in the Model Marketplace lists the groups that can use it. You can also try again later.
  • The bill differs from the marketplace price — The "All" tab shows default-group prices while your key uses another group; or the call fell in off-peak hours, the prompt exceeded the long-context threshold, or web search was used — The billed amount on each record under Usage & Logs is what counts.
  • A production app suddenly disconnects — The key was deleted or disabled — A disabled key is restored by clicking "Enable" in the list; a deleted key can only be replaced: create a new one and swap out the old key in your app.

Frequently Asked Questions

How much code do I need to change to integrate?

Usually just two things: point base_url at the gateway and replace api_key with your platform key. The gateway is compatible with official SDKs and protocols, so request bodies, response structures and the streaming format all stay the same.

Why does my bill differ from the price in the Model Marketplace?

The "All" tab shows each provider's default-group price; if your key uses a different group, you are billed at that group's price. Off-peak discounts, repricing of the whole request when the prompt exceeds the long-context threshold, and per-search billing for web search can also make a single call's cost differ from the displayed price. The billed amount on each record under Usage & Logs is what counts.

How do I control spending on one project?

Create a separate key for that project and set a monthly spend cap. Caps are per key, so projects do not affect one another; to adjust a cap later, click "Change limit" in the key list (identity verification required).

Related pages: Help Center · Guides & FAQ · AI Services · API Documentation

Loading…