# Switch AI Models at Runtime on Telnyx Edge Compute

> Source: <https://dev.to/sonam_50a41a4ced7e6b4f3fa/switch-ai-models-at-runtime-on-telnyx-edge-compute-2ncf>
> Published: 2026-08-20 22:13:11+00:00

Most AI examples hardcode the model name.

That is fine until you actually want to compare models.

If every model change requires a code edit and redeploy, experimenting gets annoying fast. The `multi-model-inference-switcher`

example turns model choice into runtime configuration instead.

Code: [https://github.com/team-telnyx/telnyx-code-examples/tree/main/multi-model-inference-switcher](https://github.com/team-telnyx/telnyx-code-examples/tree/main/multi-model-inference-switcher)

This is a TypeScript app running on Telnyx Edge Compute with the Agent SDK.

It gives you:

`active-model`

flagThe active model is read from Telnyx KV Storage every time `/chat`

is called. When you switch the model from the UI or API, the next message uses the new model immediately.

No redeploy.

``` php
GET /
  -> admin UI

POST /model
  -> validate model
  -> write active-model to KV

POST /chat
  -> read active-model from KV
  -> SwitcherAgent.process(text, model)
  -> Telnyx AI Inference
  -> return reply + model
```

The sample includes these models:

`moonshotai/Kimi-K2.6`

`zai-org/GLM-5.2`

`meta-llama/Llama-3.3-70B-Instruct`

Model choice is product behavior.

Changing the model can affect:

So it helps to make the active model observable and switchable without mixing that decision into application deploys.

Switch the active model:

```
curl -X POST https://multi-model-inference-switcher-<id>.telnyxcompute.com/model \
  -H "Content-Type: application/json" \
  -d '{"model":"zai-org/GLM-5.2"}'
```

Send a chat message:

```
curl -X POST https://multi-model-inference-switcher-<id>.telnyxcompute.com/chat \
  -H "Content-Type: application/json" \
  -d '{"text":"Explain feature flags for AI models."}'
```

Example response:

``` js
{
  "reply": "Feature flags let you change behavior at runtime...",
  "model": "zai-org/GLM-5.2"
}
```

Inspect history and usage:

```
curl https://multi-model-inference-switcher-<id>.telnyxcompute.com/history
```

The `SwitcherAgent`

uses:

The inference call looks like:

```
this.env.TELNYX.ai.openai.chat.createCompletion({
  model,
  messages,
  max_tokens: 2000,
  temperature: 0.7,
});
```

The key part is that `model`

comes from KV, not a hardcoded constant.

```
git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/multi-model-inference-switcher
npm install
```

Create and seed KV:

```
telnyx-edge storage kv create --name "switcher-flag"
telnyx-edge storage kv key put <kv-id> active-model moonshotai/Kimi-K2.6
```

Set your namespace ID in `telnyx.toml`

, add your secret, and deploy:

```
telnyx-edge secrets add TELNYX_API_KEY <YOUR_API_KEY>
telnyx-edge ship
```

Before exposing this publicly, add:

`/model`

The small idea here is powerful: keep your app deployed, but make model selection something you can operate.

Resources:
