---
title: AI Models
description: Sell AI model access through your own gateway: add your OpenAI-compatible or Anthropic-compatible providers, sync models, set prices, and let customers call one endpoint with their own keys and wallet.
url: https://nexcmp.com/docs/infrastructure/ai-models/
applies_to: NexCMP 1.6.1
updated: 2026-11-02
---

# AI Models

> **Where in the admin:** System › Admin › License & updates (`/license`) to turn the module on. Then Services › AI Models: Providers (`/ai/providers`), Models (`/ai/models`), Profit (`/ai/profit`) and Audit (`/ai/audit`). Customers use AI › API in the customer portal.

## What it does

AI Models is a gateway and billing layer on your own panel. Your customers get API keys and call **one endpoint on your domain**, in the OpenAI-compatible or the Anthropic-compatible format. You choose which models to offer and what each costs per 1 million tokens. NexCMP checks the key, the limits and the wallet, sends the request to a provider you added, meters the tokens and charges the customer's prepaid wallet.

**You bring the model sources.** NexCMP ships with no provider, no model, no default address and no price. It does not supply models, API keys, tokens or provider accounts.

::: warning Check your sources' terms first
Many model sources restrict reselling or passing access on to third parties. Use only sources you are authorized to use and to resell, and follow their terms and the law that applies to you. This page is not legal advice.
:::

AI Models is a separate product from **AI Chat and AI Agent** (module **AI**, see [AI providers](https://nexcmp.com/docs/ai/ai-providers/)). The two modules do not depend on each other.

## Requirements

| Item | Requirement |
|---|---|
| Module | **AI Models** switched on under License & updates, Modules. It is off by default. |
| Providers | One or more model sources you are authorized to resell, each with an OpenAI-compatible API (`/chat/completions`), an Anthropic-compatible API (`/messages`), or both. Each needs a base URL and an API key. |
| Network | The panel must reach each provider over **HTTPS on port 443** at a public domain name. A provider on an internal host, another port or plain HTTP must be listed under **Allowed internal hosts** (setting `ai_endpoint_allow`). |
| Customers | A customer account with a verified email address and a wallet balance. |
| Hardware | None. NexCMP only forwards requests: no GPU and no model files. |

## Prepare the infrastructure

1. Get an API key from each model source you will use, and note its base URL (for example `https://api.example.com/v1`).
2. Check the source's terms on reselling.
3. If a source runs inside your network, decide its address, for example `http://10.0.0.5:8000/v1`. You will list `10.0.0.5:8000` under **Allowed internal hosts**.

## Connect in NexCMP

### 1. Turn the module on

Open **System › Admin › License & updates**, find the card **Module**, and switch **AI Models** on. The menu reloads and **Services › AI Models** appears. While the module is off, the customer pages, the admin pages and the gateway all answer `404 module_disabled`, and no provider is contacted.

![The Module card with the AI Models switch on](https://nexcmp.com/docs/images/infrastructure/ai-models-01-modules.webp)

### 2. Add a provider

1. Open **AI Models › Providers** and choose **Add provider**.
2. Enter a short **slug**, a **name** (only you see it), the **type** (OpenAI-compatible, Anthropic-compatible or Both), the **base URL** and the **API key**, and a **priority** (a lower number is tried first).
3. Save. The key is stored encrypted and only its last four characters are shown afterwards. A key can be entered only from a signed-in administrator session.

Use **Both** only for a gateway that really serves both formats. NexCMP does **not** translate between the two formats: a model served by an OpenAI-compatible provider is reached at `/ai/v1/chat/completions`, and one served by an Anthropic-compatible provider at `/ai/v1/messages`.

![The Providers page listing three sample providers with type, priority and status](https://nexcmp.com/docs/images/infrastructure/ai-models-02-providers.webp)

### 3. Test the connection

Choose **Test connection** on the provider. NexCMP reads `GET <base URL>/models` with the key and reports **ok**, or why it failed: **auth** (wrong key), **blocked**, **billing**, or **unreachable**. A test is limited to 6 per minute.

### 4. Sync the models

Choose **Sync models**. NexCMP reads the provider's model list and adds each new model **switched off with no price**. A model the provider no longer lists is flagged. While the module is on, the list is also synced automatically every 6 hours (setting `ai_models_sync_hours`).

### 5. Set prices and switch models on

1. Open **AI Models › Models**.
2. For each model you want to sell, set the **selling price** in US dollars per 1 million tokens: **input**, **cached input** and **output**.
3. Optionally enter your **cost** for the model. Then **Profit** shows revenue against cost by day and by model, and a selling price below your cost plus the minimum margin (setting `ai_min_margin_pct`, 10 by default) is refused unless you confirm a deliberate loss. **Set price from cost** uses a markup that you choose; there is no default markup.
4. Switch the model on. A model with no selling price cannot be switched on. A cached input price left at zero is charged at the input price.

![The Models page with input, cached input and output selling prices and the on-off switches](https://nexcmp.com/docs/images/infrastructure/ai-models-03-models.webp)

### 6. Routes and failover

On a model, **Routes** lists the providers that serve it, in order. Add a second provider as a fallback, set the order, and optionally give a different model name for each provider (the name sent to the provider can differ from the name you publish). When a provider returns a server error, an authorization or billing error, a missing model or a rate limit, NexCMP tries the next route. If a read times out after the request was sent, it is **not** sent to another provider, so you do not pay twice.

Each provider is paced at `ai_provider_rpm` requests per minute (50 by default). If a provider keeps returning authorization or billing errors, NexCMP alerts the administrator on Telegram when Telegram is set up.

### 7. Open the sale switch

At the top of the AI Models pages, the **sale switch** (setting `feature_ai_models`) is off by default. While it is off, customers see that the service is not open yet and the public price list reports it as not available. Check that at least one model is on, has a selling price and a route with a key, then switch it on.

### What customers can do

In the customer portal, **AI › API**:

- **Models** shows your models and prices, the base URL and ready-made example commands.
- **API Keys**: create, rename, rotate, disable and delete keys. A secret is shown once; only a hash is stored. Per key: allowed models, expiry, a soft budget (warns) and a hard budget (blocks with `402`), requests per minute and tokens per minute.
- **Usage** by model, key and day, with export.
- **Logs**: filterable request records (time, key, model, tokens, cost, status, latency). **Prompts and responses are not recorded.** Logs are kept 90 days by default (`ai_log_retention_days`).
- **Settings**: an account budget and the email address for budget alerts.
- **Playground**: chat with a model, compare models side by side, and copy the matching code.

![The customer API Keys page with the base URLs for both API formats](https://nexcmp.com/docs/images/infrastructure/ai-models-04-keys.webp)

The gateway endpoints, on your domain:

```text
POST /ai/v1/chat/completions      OpenAI-compatible
POST /ai/v1/messages              Anthropic-compatible (also /ai/v1/messages/count_tokens)
GET  /ai/v1/models                model list
GET  /ai/v1/models/pricing        public price list, no key needed
```

### Wallet and billing

AI usage is charged to the same prepaid wallet as every other service. Before a request goes to a provider, NexCMP reserves money for the most the request could cost; if the balance is below the minimum (`ai_min_balance_cents`, 20 cents by default) or too small, the request is refused with `402 insufficient_balance` and **no provider is called**. Usage is gathered per account and settled into wallet ledger entries after each hour, with a sweep every 5 minutes; usage not yet settled is already subtracted from the balance the gateway sees.

Resellers can sell AI Models on their own domain: their markup or discount applies to your selling price and their wholesale wallet is charged the wholesale price. A per-reseller AI switch, on by default, controls who sells it.

## Verify

1. After step 3, **Test connection** shows **ok** and the model count.
2. After step 4 the new models are listed, off, with no price.
3. As a customer with a funded wallet, create a key and call the gateway:

   ```bash
   curl https://your-domain/ai/v1/chat/completions \
     -H "Authorization: Bearer sk-ai-…" -H "Content-Type: application/json" \
     -d '{"model":"model-one","messages":[{"role":"user","content":"hello"}]}'
   ```

   A `200` response carries the model's answer. **Usage** shows the request, and **Profit** shows it if you entered a cost.
4. With the wallet at zero, the same call returns `402 insufficient_balance`.

## Limits and notes

- The module has no provider, model or price built in, and no price list is ever read from a provider.
- Tools that run on the provider side and are charged per call, such as web search, are rejected because they cannot be metered. Only a short list of request parameters is passed on.
- Token usage is taken from the provider's reply; if a reply has none, NexCMP estimates it and marks the record as estimated.
- Errors from a provider are cleaned before they reach a customer (names, hosts, addresses and the provider's model name are removed). Customers never see which provider served a request.
- Customers reach the gateway through the domain of your panel, so that domain's TLS must be working.
- NexCMP does not provide a service-level agreement, fine-tuning or GPU hosting for this module.

## Troubleshooting

| Symptom | Cause and fix |
|---|---|
| Every AI Models page and the gateway answer `404 module_disabled` | The module is off. Switch **AI Models** on under License & updates, Modules. |
| Adding a provider fails with `endpoint_host_not_allowed`, `endpoint_must_be_https` or `invalid_endpoint_port` | The base URL must be HTTPS on port 443 at a public domain name. For an internal host, another port or plain HTTP, list `host:port` under **Allowed internal hosts**. |
| `blocked_endpoint` | The address is an IP, or the name resolves to a private address. List it under **Allowed internal hosts** if that is what you want. |
| **Test connection** says `auth` | The key is wrong or has no access. Enter the key again. |
| A model cannot be switched on (`no_price`) | Set a selling price first. |
| Customers get `503 ai_unavailable` | The sale switch is off, or the reseller's AI switch is off. |
| Customers get `503 upstream_unavailable` | No enabled route with a key serves that model in the requested format. Check the model's routes and the provider type. |
| Customers get `402 insufficient_balance` | The wallet is below the minimum or too small for the request. Ask the customer to top up. |
