Loading...
const res = await fetch(PROVIDER_URL, {
headers: { Authorization: 'Bearer ' + process.env.PROVIDER_KEY },
body: JSON.stringify({ model: 'model-a', messages }),
});const res = await fetch(process.env.GATEWAY_URL, {
headers: { Authorization: 'Bearer ' + process.env.GATEWAY_APP_KEY },
body: JSON.stringify({ model: 'chat-default', messages }),
});The app calls the gateway with its own key and a model alias, so provider keys and fallback rules live in one place.
An AI gateway is an API gateway specialized for model traffic: it understands tokens, model fallbacks, prompt caching and per-model costs.
A little, since every request goes through one more hop. It is usually small compared to model response time and can be offset by caching.
Yes, a simple one is a server that holds provider keys, forwards requests and logs usage. Open-source gateways add routing and fallbacks ready-made.