Axis Technologies
Back to blog

AI Gateway

AI Gateway: One Endpoint, Many Models

How we route voice, vision, text and decisions

No single AI model is best at everything. Our AI gateway sends each request to the model that fits it best, whether that's listening, seeing, writing or deciding, behind one secure API.

11 min read
  • AI Gateway
  • LLM Routing
  • Agentic AI
  • AI Software Development
Share

An AI gateway is a single entry point between your applications and your AI models. Every request, whether it's a voice command, a photo, a chat message or a business decision, goes through the gateway. The gateway checks it, picks the model best suited to the job and returns the answer through one consistent API.

We're building our own custom AI gateway at Axis Technologies, because the projects we deliver no longer use just one model. A single customer workflow might need to listen to a phone call, read a scanned delivery note, write a reply and decide whether a refund needs approval. No single model is the best, cheapest and fastest at all four.

This article explains what an AI gateway does, how intelligent model routing works, and what we've learned so far building one for voice, vision, text and decisions.

Figure 1One big model for everything, or the right model for each job?

One big model

Simple to start, expensive to scale

  • Every request pays the price of the largest model
  • Slow answers even for simple questions
  • Weak or missing support for voice and images
  • All data goes to the same provider
  • One outage stops everything

AI gateway with many models

The right model for each request

  • Small models handle easy requests quickly and cheaply
  • Large models are kept for hard reasoning
  • Specialist models for speech, images and search
  • Sensitive data can stay on your own servers
  • Fallback to another model when one is down
Section

Why one AI model isn't enough

When teams start with AI, they usually connect one app to one large model. It works, until it doesn't. Four problems tend to appear at the same time:

  • Cost. Most requests are simple: "summarise this", "classify that", "is this an invoice?". Sending them all to the largest model is like hiring a senior engineer to sort the post.
  • Speed. Large models take longer to answer. For a voice assistant or a live chat, a two-second delay feels broken.
  • Different kinds of input. Text models don't hear and many don't see. Voice needs speech-to-text and text-to-speech. Images need a vision model. Document search needs embedding and reranking models.
  • Control. Some data shouldn't leave your network. Some tasks need an audit trail. Some providers have outages. You need one place to manage all of that.

An AI gateway solves these problems in one layer instead of in every application.

Section

How our AI gateway works

Think of the gateway as a smart receptionist. Every request comes to the same desk. The receptionist checks your badge, makes sure the request is safe, understands what you need and sends you to the right specialist.

Figure 2Inside our AI gateway
  1. 01

    Your applications

    web apps · agents · voice devices

    Everything talks to one OpenAI-compatible endpoint, with one key per app.

    • web apps
    • Mastra agents
    • voice assistants
    • n8n
  2. 02

    Security

    auth · safety

    Checks who is asking, screens for prompt injection and masks personal data.

    • API keys
    • injection check
    • PII masking
  3. 03

    Intelligent router

    the decision layer

    Looks at the type of input and the difficulty of the request, then chooses the model.

    • modality
    • difficulty
    • context size
    • tool support
  4. 04

    Specialist models

    self-hosted + cloud

    Each model has one job it does well, sized to the hardware it runs on.

    • small LLM
    • large LLM
    • vision
    • speech
    • embeddings
  5. 05

    Observability

    logs · costs · quality

    Every request is logged with the chosen model, tokens, cost and response time.

    • traces
    • cost per app
    • latency

Because the gateway speaks the same API format as OpenAI, our apps don't need special code. They point at the gateway and ask for the model auto:

lib/ai.tsts
import OpenAI from 'openai';export const ai = new OpenAI({  baseURL: process.env.AI_GATEWAY_URL, // our gateway, not a provider  apiKey: process.env.AI_GATEWAY_KEY,});const reply = await ai.chat.completions.create({  model: 'auto', // let the gateway choose the right model  messages: [{ role: 'user', content: 'Summarise this delivery note and list any missing items.' }],});

Switching a model, adding a new one or moving a task from the cloud to our own hardware happens in the gateway. None of the applications change.

Section

Intelligent model routing: the right model for every request

Routing is the heart of an AI gateway. For every request, the router answers one question: which model should handle this?

Figure 3What happens to a request inside the gateway
  1. 01

    Receive

    Request arrives

    Text, audio, an image, or a mix, sent with model “auto”.

  2. 02

    Check

    Security first

    Key verified, injection check run, personal data masked.

  3. 03

    Classify

    Understand the request

    What kind of input is it? How hard is it? Does it need tools or a long context?

  4. 04

    Route

    Pick the model

    Easy goes to the small model, hard to the large one, images and audio to specialists.

  5. 05

    Answer

    Reply and log

    The answer returns, along with which model was used, the cost and the time taken.

The router itself is a small, fast model. Its only job is to make that decision in a few milliseconds. It considers:

  • Modality. Does the request contain audio, an image, or only text?
  • Difficulty. A quick yes/no or a short summary is "easy". Multi-step reasoning, code or long documents are "hard". Easy requests go to the small model; everything else goes to the large one.
  • Capabilities. Does the request need tool calling? Is it longer than a model's context window? Does the answer need to be long? A model that can't meet those needs is never chosen, however cheap it is.
  • Policy. Some apps or data types must stay on our own servers. Some tasks always need the strongest model.

Every response tells the app which model was chosen, so we can audit the router and spot bad decisions. Open-source projects such as vLLM Semantic Router have made this kind of routing much more practical in the last year.

Section

Voice AI: listening and speaking

Voice is where a gateway really pays off, because one spoken request uses several models in a row.

Figure 4A voice request, end to end
  1. 01

    Speech-to-text

    Listen

    A speech model such as Whisper turns audio into text.

  2. 02

    Route

    Understand

    The gateway sends the text to a fast model. Voice can't wait for the largest one.

  3. 03

    Act

    Do the job

    Tools look up an order, book a slot or control a device.

  4. 04

    Text-to-speech

    Reply

    A speech model such as Kokoro reads the answer aloud.

Speed matters more than anything here. That's why speech models run on dedicated hardware close to the user, and why voice requests usually go to a small, quick language model. A brilliant answer that arrives three seconds late is worse than a good answer that arrives now.

Typical uses we're designing for: phone and helpdesk assistants, hands-free checklists for operators on the shop floor, and voice control for internal tools.

Section

Vision AI: reading images and documents

Many business processes still run on pictures: scanned invoices, photos of delivery notes, screenshots of error messages, quality-control photos from a production line.

When a request contains an image, the gateway sends it through a vision encoder first. The encoder turns the picture into something a language model can reason about. Then the router decides whether a small model can handle the question ("what's the invoice total?") or whether it needs the large one ("compare this delivery note with the order and list what's missing").

The lesson we keep relearning: getting a vision model to describe a picture is easy. Getting it to read the picture, use a tool and take the right action reliably is a separate step that has to be tested end to end.

Section

Decisions: where the gateway meets agents

Not every request is a question. Many are decisions: should this refund be approved? Is this email a complaint? Which team should handle this ticket?

For decisions, the gateway works together with our AI agents. The gateway provides the right model for each step. The agent, built with Next.js and Mastra, owns the logic: which tools to call, which rules apply and when to ask a person.

A few rules we follow for decisions:

  • The model suggests, the rules decide. Anything with money, safety or legal weight goes through a fixed workflow with clear thresholds.
  • Confidence matters. Low-confidence decisions go to a person automatically.
  • Everything is traceable. For every decision we can see which model was used, what it saw and why it chose what it did.
Section

Security built in: prompt injection detection and data protection

Putting all AI traffic through one gateway is also a big security win. Instead of protecting every app separately, we protect one door.

  • Prompt injection detection. A dedicated classifier checks requests for attempts to override instructions or extract hidden data. We start in monitoring mode, so it only records what it finds. That lets us measure false alarms on real traffic before we block anything.
  • Personal data masking. Names, emails and other sensitive fields can be masked before a request reaches an external provider.
  • Keys and limits per app. Every application has its own key, budget and rate limit. A bug in one app can't burn through everyone's budget.
  • A full audit log. Who asked what, which model answered, and what it cost.
Section

Self-hosted, cloud or both?

One of the main reasons to build a gateway is the freedom to choose where each model runs.

Figure 5Where should your models run?

Self-hosted models

On your own servers or GPUs

  • Sensitive data never leaves your network
  • Predictable cost once the hardware is paid for
  • Older or smaller GPUs can each run one focused model
  • You manage updates and capacity

Cloud models

From AI providers

  • The most capable models are available instantly
  • Nothing to install or maintain
  • Pay per use, which adds up at high volume
  • Data leaves your network, under the provider's terms

Our default is hybrid: everyday and sensitive work on our own hardware, the hardest tasks in the cloud, and the gateway decides per request.

A point that surprises many people: you don't need the biggest, newest GPU to run useful AI. Giving each model one focused job lets you match it to modest hardware. A small model for quick answers, an embedding model for search and speech models on a low-power chip can share one server. The large model is only woken up when it's really needed.

Section

AI gateway vs API gateway

People often ask whether their existing API gateway can do this. Partly, yes: authentication, rate limits and logging are the same idea. The difference is that an AI gateway understands the request. It knows whether there's an image inside, how hard the question is, how many tokens it will cost and which model can handle it. It also deals with risks that classic gateways were never built for, like prompt injection.

In practice we often run both: the API gateway at the edge of the network, and the AI gateway behind it for everything that touches a model.

Section

What we've learned so far

Building our AI gateway has taught us a few lessons we'd share with anyone starting out:

  1. Get routing right before chasing savings. A wrong routing decision looks exactly like a bad model. Check that requests go where they should before you optimise anything.
  2. Capabilities beat clever prompts. Whether a model supports tools, how big its context is and how long its answers can be matter more than how you word the prompt.
  3. A good search score isn't a correct answer. In document search, check that the retrieved passages are really the right evidence, not just similar text.
  4. Test every path end to end. "The vision model runs" is not the same as "the vision workflow works". Each modality needs its own real-world tests.
  5. Log the decision, not just the answer. Knowing which model answered, and why, is what makes the system debuggable.
Figure 6How we introduce an AI gateway in a project
  1. 01

    Week 1

    Map the requests

    List every AI call your apps make: type of input, volume, sensitivity.

  2. 02

    Weeks 2–3

    Gateway in front

    Point apps at one endpoint. Same models as before, now with logs and limits.

  3. 03

    Weeks 4–6

    Add routing

    Introduce small and specialist models and compare quality, cost and speed.

  4. 04

    Ongoing

    Tune and expand

    Adjust routing from real traffic and add voice or vision when needed.

Section

The short version

As soon as your business uses AI for more than one thing, an AI gateway stops being a nice-to-have. It gives every app one simple API, sends each request to the model that fits it best, keeps sensitive data where it belongs and shows you exactly what your AI is doing and what it costs.

We're building ours for voice, vision, text and decisions, and using it inside the agent-powered software we deliver to clients. If you're running into the limits of a single model, or want to bring AI onto your own hardware, get in touch. We'd be happy to show you how routing could work for your workflows.

Further watching: Techno Tim's video I Built My Own Intelligent AI Gateway is a great hands-on look at running several self-hosted models behind one intelligent router.

Found this useful? Share it with your team.

AI gateway FAQ

Frequently asked questions about AI gateways

What teams ask us when they start using more than one AI model.

Let's Build Something Amazing Together

Ready to transform your business with cutting-edge digital solutions? Our team of experts is here to bring your vision to life.