> 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 Blocklist Rule

POST https://api-gateway.merge.dev/v1/blocklist-rules
Content-Type: application/json

Create a rule that blocks or pins models and providers for customers,
or for everyone. An organization can have up to 100 rules; changes apply
to new requests within seconds.

Reference: https://docs.merge.dev/merge-gateway/management-api/security-rules/create-blocklist-rule

## Authentication

- `Authorization` header (bearer token, required) — A management key (`mgmt_...`), sent as `Authorization: Bearer <key>`. Reading /v1/routing-policies also accepts the organization's gateway API keys; writing there needs a management key.

## Request

### Body (application/json)

This endpoint expects a BlocklistRuleV1Create.

- `customer_ids` (list of string, optional) — Values of the `X-Customer-ID` request header the rule applies to. Empty matches every customer. Empty strings are dropped. A block rule needs at least one non-empty list.
- `models` (list of string, optional) — Full model ids, like `openai/gpt-5.5`. Empty strings are dropped. A block rule needs at least one non-empty list.
- `providers` (list of string, optional) — Model providers, the prefix of a model id, like `anthropic`. With `models` empty too, matches every model. Empty strings are dropped. A block rule needs at least one non-empty list.
- `reason` (string, optional, default: ) — Why the rule exists, such as a ticket or contract clause.
- `rule_type` (enum, optional, default: block) — `block` denies a request when its customer matches and its model or provider matches. `pin` lets the listed customers use only the listed providers and models, and needs `customer_ids` plus `providers` or `models`. A block always wins over a pin.
  - Allowed values: `block`, `pin`

## Response

### 201

The created blocklist rule

- `created_at` (datetime, required) — When the rule was created.
- `customer_ids` (list of string, required) — Values of the `X-Customer-ID` request header the rule applies to. Empty matches every customer.
- `id` (string, required) — The rule's id.
- `models` (list of string, required) — Full model ids, like `openai/gpt-5.5`.
- `providers` (list of string, required) — Model providers, the prefix of a model id, like `anthropic`. With `models` empty too, matches every model.
- `reason` (string, required) — Why the rule exists, such as a ticket or contract clause.
- `rule_type` (enum, required) — `block` denies a request when its customer matches and its model or provider matches. `pin` lets the listed customers use only the listed providers and models, and needs `customer_ids` plus `providers` or `models`. A block always wins over a pin.
  - Allowed values: `block`, `pin`
- `updated_at` (datetime, required) — When the rule last changed.

## Errors

### 400 Bad Request Error

The organization already has 100 rules.

- `detail` (ErrorResponseDetail, required) — A message, or an object with a `code` to branch on and a `message`.

### 401 Unauthorized Error

The key is missing or invalid.

- `detail` (ErrorResponseDetail, required) — A message, or an object with a `code` to branch on and a `message`.

### 403 Forbidden Error

The key lacks the scope this route needs, or the change is not allowed.

- `detail` (ErrorResponseDetail, required) — A message, or an object with a `code` to branch on and a `message`.

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### ErrorResponseDetail

A message, or an object with a `code` to branch on and a `message`.

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `ctx` (ValidationErrorCtx, optional)
- `input` (any, optional)

### ErrorDetail

A structured error. Some carry extra fields, like `count`.

- `code` (string, required) — A stable code to branch on, like `payment_method_required`.
- `message` (string, required) — A human-readable explanation.

### ValidationErrorLocItems

### ValidationErrorCtx

## Examples

**Request**

```json
{
  "customer_ids": [
    "cus_trial_4821"
  ],
  "models": [
    "openai/gpt-5.5"
  ],
  "providers": [],
  "reason": "Trial customers can't use GPT-5.5.",
  "rule_type": "block"
}
```

**Response**

```json
{
  "created_at": "2026-06-02T17:04:00Z",
  "customer_ids": [
    "cus_trial_4821"
  ],
  "id": "9e1c5a3f-7b2d-4a8e-b6c0-2d4f6a8c0e35",
  "models": [
    "openai/gpt-5.5"
  ],
  "providers": [],
  "reason": "Trial customers can't use GPT-5.5.",
  "rule_type": "block",
  "updated_at": "2026-09-14T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api-gateway.merge.dev/v1/blocklist-rules"

payload = {
    "customer_ids": ["cus_trial_4821"],
    "models": ["openai/gpt-5.5"],
    "providers": [],
    "reason": "Trial customers can't use GPT-5.5.",
    "rule_type": "block"
}
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/blocklist-rules';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"customer_ids":["cus_trial_4821"],"models":["openai/gpt-5.5"],"providers":[],"reason":"Trial customers can\'t use GPT-5.5.","rule_type":"block"}'
};

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/blocklist-rules"

	payload := strings.NewReader("{\n  \"customer_ids\": [\n    \"cus_trial_4821\"\n  ],\n  \"models\": [\n    \"openai/gpt-5.5\"\n  ],\n  \"providers\": [],\n  \"reason\": \"Trial customers can't use GPT-5.5.\",\n  \"rule_type\": \"block\"\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/blocklist-rules")

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  \"customer_ids\": [\n    \"cus_trial_4821\"\n  ],\n  \"models\": [\n    \"openai/gpt-5.5\"\n  ],\n  \"providers\": [],\n  \"reason\": \"Trial customers can't use GPT-5.5.\",\n  \"rule_type\": \"block\"\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/blocklist-rules")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"customer_ids\": [\n    \"cus_trial_4821\"\n  ],\n  \"models\": [\n    \"openai/gpt-5.5\"\n  ],\n  \"providers\": [],\n  \"reason\": \"Trial customers can't use GPT-5.5.\",\n  \"rule_type\": \"block\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-gateway.merge.dev/v1/blocklist-rules', [
  'body' => '{
  "customer_ids": [
    "cus_trial_4821"
  ],
  "models": [
    "openai/gpt-5.5"
  ],
  "providers": [],
  "reason": "Trial customers can\'t use GPT-5.5.",
  "rule_type": "block"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api-gateway.merge.dev/v1/blocklist-rules");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"customer_ids\": [\n    \"cus_trial_4821\"\n  ],\n  \"models\": [\n    \"openai/gpt-5.5\"\n  ],\n  \"providers\": [],\n  \"reason\": \"Trial customers can't use GPT-5.5.\",\n  \"rule_type\": \"block\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "customer_ids": ["cus_trial_4821"],
  "models": ["openai/gpt-5.5"],
  "providers": [],
  "reason": "Trial customers can't use GPT-5.5.",
  "rule_type": "block"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api-gateway.merge.dev/v1/blocklist-rules")! 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()
```