One Capped Gateway Key per Customer

Serve your product's customers through one endpoint, with a separate monthly Waygate fee cap and request rate for each customer's key.

The Route: Support bot

Both customer keys use the same route to OpenAI.

Requestfrom your SDK
OpenAIgpt-6.1-sol
Requestfrom your SDK
OpenAIgpt-6.1-sol

Create one endpoint for your product

For a support product serving Acme and Birch, use one Support bot endpoint and two gateway keys. Your backend chooses the key for the authenticated customer on every request.

  • 1. Add a provider: on Providers, add an OpenAI provider named OpenAI with your own provider key. Test it before using it. Provider keys stay in Model Waygate, encrypted; your application uses gateway keys.
  • 2. New endpoint: name it Support bot; the slug becomes support-bot. Choose One model, then Provider OpenAI and Model gpt-6.1-sol. Create Endpoint opens its settings. The diagram above is that route, shared by both customers.

Mint a key for each customer

On the endpoint's settings page, use Mint a Key twice. Both keys call the same endpoint URL and no other endpoint.

  • Acme: set Name to customer-acme, Monthly cap ($) to 2, and Requests per minute to 30; click Mint Key. Copy the key shown once into your backend's secret store against Acme's customer id.
  • Birch: repeat with Name customer-birch, Monthly cap ($) 2, and Requests per minute 30. Store this separate key against Birch. Never let a caller supply another customer's key or select their customer identity.
  • Change or revoke: the Keys table lets you change the name, Monthly cap ($) and Requests per minute, then Save. Disable stops that key without affecting its sibling; Delete removes it. Blank monthly cap inherits the account cap; blank rate inherits the gateway default.
  • Rate limits: a key's request limit can only narrow the gateway default. The account also has a shared minute limit: two keys do not double it. Excess inference requests receive HTTP 429 with error type rate_limit_exceeded and Retry-After; a key-scoped refusal does not consume a sibling's allowance.

Send a request for Acme

Use mw_your_gateway_key as a placeholder for Acme's stored key below. For Birch, use Birch's key with exactly the same URL and body. Copy the real endpoint URL from settings; USER_ID stands for your account's public id.

  • Backend only: keep the key in a secret store or environment variable, never in frontend code or source control. The required model field is a label: the endpoint's route chooses the model.

Code Examples

curl https://modelwaygate.com/USER_ID/support-bot/api/v1/chat/completions \
  -H "Authorization: Bearer mw_your_gateway_key" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "support-bot",
  "messages": [
    {"role": "system", "content": "You answer questions about orders in one short paragraph."},
    {"role": "user", "content": "Where is order 1042?"}
  ]
}'
from openai import OpenAI

client = OpenAI(base_url="https://modelwaygate.com/USER_ID/support-bot/api/v1", api_key="mw_your_gateway_key")

response = client.chat.completions.create(
    model="support-bot",
    messages=[
        {"role": "system", "content": "You answer questions about orders in one short paragraph."},
        {"role": "user", "content": "Where is order 1042?"},
    ],
)
print(response.model, response.choices[0].message.content)
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://modelwaygate.com/USER_ID/support-bot/api/v1", apiKey: "mw_your_gateway_key" });

const response = await client.chat.completions.create({
  model: "support-bot",
  messages: [
    { role: "system", content: "You answer questions about orders in one short paragraph." },
    { role: "user", content: "Where is order 1042?" },
  ],
});
console.log(response.model, response.choices[0].message.content);
OkHttpClient client = new OkHttpClient();

String json = "{\"model\": \"support-bot\", \"messages\": ["
    + "{\"role\": \"system\", \"content\": \"You answer questions about orders in one short paragraph.\"}, "
    + "{\"role\": \"user\", \"content\": \"Where is order 1042?\"}]}";

Request request = new Request.Builder()
    .url("https://modelwaygate.com/USER_ID/support-bot/api/v1/chat/completions")
    .header("Authorization", "Bearer mw_your_gateway_key")
    .post(RequestBody.create(json, MediaType.get("application/json")))
    .build();

try (Response response = client.newCall(request).execute()) {
    System.out.println(response.body().string());
}
import Data.Aeson (encode, object, (.=))
import Network.HTTP.Client
import Network.HTTP.Client.TLS (tlsManagerSettings)

main :: IO ()
main = do
  manager <- newManager tlsManagerSettings
  initial <- parseRequest "POST https://modelwaygate.com/USER_ID/support-bot/api/v1/chat/completions"
  let turn role content = object ["role" .= (role :: String), "content" .= (content :: String)]
      body = object ["model" .= ("support-bot" :: String), "messages" .= [turn "system" "You answer questions about orders in one short paragraph.", turn "user" "Where is order 1042?"]]
      request = initial{requestHeaders = [("Authorization", "Bearer mw_your_gateway_key"), ("Content-Type", "application/json")], requestBody = RequestBodyLBS (encode body)}
  response <- httpLbs request manager
  print (responseBody response)

When Acme reaches its monthly cap

Once Acme's recorded monthly spend reaches $2, its next inference request is refused before any provider is called. Birch can still use its own key while its own cap and the shared account limits allow it.

  • The response: HTTP 402, error type insufficient_quota, message Monthly spend cap reached for this key. Handle it as a budget refusal, rather than immediately retrying. Raise the key's cap with Save or wait for the next calendar month (UTC).
  • What the cap covers: this is a cap on Model Waygate's byte fees, not your provider's bill. Providers bill you directly under your provider keys. The free monthly byte allowance applies to the account; an unsubscribed account cannot continue beyond it.
  • Shared account cap: the effective key cap is the lower of its own cap and the account cap. The account's total spend across all keys can stop both customers, with the message Monthly spend cap reached for this account. Check Billing before raising caps; raising the account cap above the default needs an active subscription.
  • Requests in flight: caps are checked when requests start. Requests already admitted still finish and are billed, so concurrent requests can take spend past a cap. These caps are not a strict ceiling on your total provider costs.

Read usage for each key

Call the informational API with the customer's bearer key, including after its cap is reached. These GETs are not rate limited.

  • This key: GET https://modelwaygate.com/USER_ID/support-bot/api/v1/key returns data.label, effective monthly cap data.limit and this month's Waygate fee data.usage in dollars, plus data.usage_bytes, data.endpoint and data.rate_limit (requests and interval). Replace the request above with a GET to this URL, keeping its Authorization header and omitting its body.
  • Compare account and key: GET https://modelwaygate.com/USER_ID/support-bot/api/v1/credits returns data.total_credits, data.total_usage and data.total_bytes for the account, and data.key for this key's share. Query once with Acme's key and once with Birch's to read each customer's usage.
  • Investigate a request: use the dashboard's Usage page and the individual request page for status, bytes, fees and route taken. Keep the mapping from your customer ids to key names in your backend.

Ready to get started?

Create Your API Key