> This page is for Gateway.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.merge.dev/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.merge.dev/_mcp/server.

# Create a routing policy

POST https://api-gateway.merge.dev/v1/routing-policies
Content-Type: application/json

Create an org routing policy. The first policy becomes the org default automatically. Requires the manage_routing scope.

Authenticates with a management key (manage_routing scope) or any active gateway API key of the organization.

Reference: https://docs.merge.dev/merge-gateway/management-api/routing-policies/create-routing-policy

## Authentication

- `Authorization` header (bearer token, required) — A management key (prefixed `mgmt_`), created on the dashboard's **API keys** page under **Management keys**. Distinct from a regular gateway API key, and never used to call models.

## Request

### Body (application/json)

This endpoint expects an OrgRoutingPolicyCreate.

- `name` (string, required)
- `strategy` (enum, required)
  - Allowed values: `PRIORITY`, `INTELLIGENT`
- `description` (string, optional)
- `slug` (string, optional) — Explicit model alias for the new policy (bare name, lowercase slug). Omitted: derived from the name, or "default" when the policy becomes the organization default. Collisions are suffixed ("fast", "fast-2").
- `is_default` (boolean, optional) — Make this the org default (unsets the previous default).
- `allowed_providers` (list of string, optional) — INTELLIGENT only, optional. If provided, must match the providers of allowed_models (it does not filter independently); returned derived from allowed_models on reads.
- `allowed_models` (list of string, optional) — INTELLIGENT only.
- `priority_order` (list of PriorityEntry, optional) — PRIORITY only.
- `axis` (enum, optional) — INTELLIGENT only. Optimization axis the router optimizes for; defaults to COST.
  - Allowed values: `COST`, `PERFORMANCE`, `CAPABILITY`

## Response

### 201

The created policy.

- `id` (string, optional)
- `name` (string, optional)
- `description` (string, optional)
- `slug` (string, optional, nullable) — The policy's model alias (bare name), e.g. "fast-experiment". Null only when no alias could be minted, such as an organization at its alias cap.
- `model` (string, optional, nullable) — The ready-to-send model string for this policy, e.g. "@alias/fast-experiment". Send it as the model in any Gateway request to route with this policy.
- `strategy` (enum, optional)
  - Allowed values: `PRIORITY`, `INTELLIGENT`
- `allowed_providers` (list of string, optional)
- `allowed_models` (list of string, optional)
- `priority_order` (list of PriorityEntry, optional)
- `axis` (enum, optional) — Optimization axis the router optimizes for (INTELLIGENT only, else null); one of COST, PERFORMANCE, CAPABILITY.
  - Allowed values: `COST`, `PERFORMANCE`, `CAPABILITY`
- `created_at` (datetime, optional)
- `modified_at` (datetime, optional)

## Errors

### 422 Unprocessable Entity Error

Validation error (e.g. PRIORITY mixed with allowed_models).

- `detail` (string, optional) — Human-readable error message.

## Types

### PriorityEntry

- `model` (string, required) — Canonical model slug (provider/model).
- `priority` (integer, required) — Lower tries first.

## Examples

**Request**

```json
{
  "name": "string",
  "strategy": "PRIORITY"
}
```

**Response**

```json
{
  "id": "string",
  "name": "string",
  "description": "string",
  "slug": "string",
  "model": "string",
  "strategy": "PRIORITY",
  "allowed_providers": [
    "string"
  ],
  "allowed_models": [
    "string"
  ],
  "priority_order": [
    {
      "model": "openai/gpt-5.5",
      "priority": 1
    }
  ],
  "axis": "COST",
  "created_at": "2024-01-15T09:30:00Z",
  "modified_at": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api-gateway.merge.dev/v1/routing-policies"

payload = {
    "name": "string",
    "strategy": "PRIORITY"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api-gateway.merge.dev/v1/routing-policies';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"string","strategy":"PRIORITY"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api-gateway.merge.dev/v1/routing-policies"

	payload := strings.NewReader("{\n  \"name\": \"string\",\n  \"strategy\": \"PRIORITY\"\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(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api-gateway.merge.dev/v1/routing-policies")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"string\",\n  \"strategy\": \"PRIORITY\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-gateway.merge.dev/v1/routing-policies")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"string\",\n  \"strategy\": \"PRIORITY\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-gateway.merge.dev/v1/routing-policies', [
  'body' => '{
  "name": "string",
  "strategy": "PRIORITY"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api-gateway.merge.dev/v1/routing-policies");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"string\",\n  \"strategy\": \"PRIORITY\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "string",
  "strategy": "PRIORITY"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api-gateway.merge.dev/v1/routing-policies")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```