Create a Model Route - Barndoor Documentation
Create a model route
cURL
curl --request POST \
--url https://app.barndoor.ai/api/llm-gateway/admin/model-mappings \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"provider_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"model_alias": "<string>",
"upstream_model": "<string>",
"enabled": true,
"priority": 0,
"retry_on_429_count": 0,
"retry_on_429_max_wait_secs": 0,
"bare_alias": true,
"stream_idle_timeout_secs": 900,
"max_concurrent_requests": 5000,
"request_timeout_secs": 1800
}
'```
### Python Example
```python
import requests
url = "https://app.barndoor.ai/api/llm-gateway/admin/model-mappings"
payload = {
"provider_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"model_alias": "<string>",
"upstream_model": "<string>",
"enabled": True,
"priority": 0,
"retry_on_429_count": 0,
"retry_on_429_max_wait_secs": 0,
"bare_alias": True,
"stream_idle_timeout_secs": 900,
"max_concurrent_requests": 5000,
"request_timeout_secs": 1800
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
JavaScript Example
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
provider_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
model_alias: '<string>',
upstream_model: '<string>',
enabled: true,
priority: 0,
retry_on_429_count: 0,
retry_on_429_max_wait_secs: 0,
bare_alias: true,
stream_idle_timeout_secs: 900,
max_concurrent_requests: 5000,
request_timeout_secs: 1800
})
};
fetch('https://app.barndoor.ai/api/llm-gateway/admin/model-mappings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
Go Example
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.barndoor.ai/api/llm-gateway/admin/model-mappings"
payload := strings.NewReader("{\n \"provider_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"model_alias\": \"<string>\",\n \"upstream_model\": \"<string>\",\n \"enabled\": true,\n \"priority\": 0,\n \"retry_on_429_count\": 0,\n \"retry_on_429_max_wait_secs\": 0,\n \"bare_alias\": true,\n \"stream_idle_timeout_secs\": 900,\n \"max_concurrent_requests\": 5000,\n \"request_timeout_secs\": 1800\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}
PHP Example
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.barndoor.ai/api/llm-gateway/admin/model-mappings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'provider_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'model_alias' => '<string>',
'upstream_model' => '<string>',
'enabled' => true,
'priority' => 0,
'retry_on_429_count' => 0,
'retry_on_429_max_wait_secs' => 0,
'bare_alias' => true,
'stream_idle_timeout_secs' => 900,
'max_concurrent_requests' => 5000,
'request_timeout_secs' => 1800
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Example Response
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"provider_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"model_alias": "gpt-4o-mini",
"upstream_model": "gpt-4o-mini-2024-07-18",
"enabled": true,
"priority": 123,
"retry_on_429_count": 5,
"retry_on_429_max_wait_secs": 90,
"bare_alias": true,
"provider_name": "<string>",
"stream_idle_timeout_secs": 900,
"max_concurrent_requests": 5000,
"request_timeout_secs": 1800,
"budget_status": {
"scope": "org",
"target_id": "<string>",
"budget_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"budget_name": "<string>",
"period": "monthly",
"usage": 123,
"limit": 123
}
}
Error Response
{
"error": "BadRequest",
"message": "request_timeout_secs must be between 1 and 3600"
}
A Model Route maps a client-facing alias to a (provider, upstream model) pair. Multiple routes can share the same model_alias — the gateway tries them in priority order (lowest first) and fails over to the next on upstream errors.
Two kinds of routes
- 1:1 enablement (
model_alias == upstream_model) — exposes the upstream model under its own name, addressable as<provider>/<upstream_model>. Defaults tobare_alias: false. - Custom alias (
model_alias != upstream_model) — exposes the model under a friendly alias (e.g.team-coding-model). Defaults tobare_alias: trueso callers can use the plain name inmodel. Requires an existing 1:1 enablement on the same(provider, upstream_model)pair.