The Route: Support bot
Both customer keys use the same route to OpenAI.
Serve your product's customers through one endpoint, with a separate monthly Waygate fee cap and request rate for each customer's key.
Both customer keys use the same route to OpenAI.
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.
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.On the endpoint's settings page, use Mint a Key twice. Both keys call the same endpoint URL and no other endpoint.
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.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.rate_limit_exceeded and Retry-After; a key-scoped refusal does not consume a sibling's allowance.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.
model field is a label: the endpoint's route chooses the model.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)
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.
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).Monthly spend cap reached for this account. Check Billing before raising caps; raising the account cap above the default needs an active subscription.Call the informational API with the customer's bearer key, including after its cap is reached. These GETs are not rate limited.
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.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.