> 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.

# Update Key Set

PUT https://api-gateway.merge.dev/v1/key-sets/{key_set_id}
Content-Type: application/json

Replace the set's name, strategy, members and managed fallback. The vendor can't change.

Reference: https://docs.merge.dev/merge-gateway/management-api/key-sets/update-key-set

## 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

### Path parameters

- `key_set_id` (string, required) — The key set's `id`.

### Body (application/json)

This endpoint expects a KeySetV1Update.

- `members` (list of KeySetMemberV1, required) — The keys in the set, by credential `id`. Each must be one of the organization's own keys for the set's vendor. At most 1000.
- `name` (string, required) — A name for the set.
- `strategy` (enum, required) — How traffic is spread across the members. `failover` tries them in order. `weighted` spreads requests by weight and keeps each conversation on one key. `round_robin` does the same with equal weights.
  - Allowed values: `failover`, `weighted`, `round_robin`
- `fallback_to_managed` (boolean, optional, default: true) — When no key in the set can serve a request, use Merge-managed access for the vendor, if the organization has it. When false, the request fails instead.

## Response

### 200

The updated key set

- `created_at` (datetime, required, nullable) — When the set was created.
- `fallback_to_managed` (boolean, required) — When no key in the set can serve a request, use Merge-managed access for the vendor, if the organization has it. When false, the request fails instead.
- `id` (string, required) — The key set's id.
- `members` (list of KeySetMemberV1, required) — The keys in the set, by credential `id`. Each must be one of the organization's own keys for the set's vendor. At most 1000.
- `name` (string, required) — The set's name.
- `strategy` (string, required) — How traffic is spread across the members. `failover` tries them in order. `weighted` spreads requests by weight and keeps each conversation on one key. `round_robin` does the same with equal weights.
- `updated_at` (datetime, required, nullable) — When the set last changed.
- `vendor` (string, required) — The vendor's slug.

## Errors

### 400 Bad Request Error

A member isn't one of the organization's own keys for the set's vendor, or the set is otherwise invalid.

- `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`.

### 404 Not Found Error

The resource does not exist in the key's organization.

- `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)

### 503 Service Unavailable Error

A service the request needs, such as billing or the gateway itself, is temporarily unavailable. Retry later.

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

## Types

### KeySetMemberV1

- `credential_id` (string, required) — The credential's `id`.
- `weight` (integer, optional, nullable) — Share of traffic under `weighted`. null means 1.

### ErrorResponseDetail

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

- string
- ErrorDetail: ErrorDetail

### 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

- string
- integer

### ValidationErrorCtx

## Examples

**Request**

```json
{
  "members": [
    {
      "credential_id": "6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81",
      "weight": null
    }
  ],
  "name": "bedrock-team-a",
  "strategy": "failover",
  "fallback_to_managed": false
}
```

**Response**

```json
{
  "created_at": "2026-06-02T17:04:00Z",
  "fallback_to_managed": false,
  "id": "3f8e2c1a-7b4d-4e9a-a6c2-5d1b8f0e7a93",
  "members": [
    {
      "credential_id": "6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81",
      "weight": 2
    }
  ],
  "name": "bedrock-team-a",
  "strategy": "weighted",
  "updated_at": "2026-09-14T09:30:00Z",
  "vendor": "bedrock"
}
```

**SDK Code**

```python
import requests

url = "https://api-gateway.merge.dev/v1/key-sets/key_set_id"

payload = {
    "members": [
        {
            "credential_id": "6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81",
            "weight": None
        }
    ],
    "name": "bedrock-team-a",
    "strategy": "failover",
    "fallback_to_managed": False
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api-gateway.merge.dev/v1/key-sets/key_set_id';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"members":[{"credential_id":"6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81","weight":null}],"name":"bedrock-team-a","strategy":"failover","fallback_to_managed":false}'
};

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/key-sets/key_set_id"

	payload := strings.NewReader("{\n  \"members\": [\n    {\n      \"credential_id\": \"6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81\",\n      \"weight\": null\n    }\n  ],\n  \"name\": \"bedrock-team-a\",\n  \"strategy\": \"failover\",\n  \"fallback_to_managed\": false\n}")

	req, _ := http.NewRequest("PUT", 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/key-sets/key_set_id")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"members\": [\n    {\n      \"credential_id\": \"6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81\",\n      \"weight\": null\n    }\n  ],\n  \"name\": \"bedrock-team-a\",\n  \"strategy\": \"failover\",\n  \"fallback_to_managed\": false\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.put("https://api-gateway.merge.dev/v1/key-sets/key_set_id")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"members\": [\n    {\n      \"credential_id\": \"6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81\",\n      \"weight\": null\n    }\n  ],\n  \"name\": \"bedrock-team-a\",\n  \"strategy\": \"failover\",\n  \"fallback_to_managed\": false\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api-gateway.merge.dev/v1/key-sets/key_set_id', [
  'body' => '{
  "members": [
    {
      "credential_id": "6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81",
      "weight": null
    }
  ],
  "name": "bedrock-team-a",
  "strategy": "failover",
  "fallback_to_managed": false
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api-gateway.merge.dev/v1/key-sets/key_set_id");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"members\": [\n    {\n      \"credential_id\": \"6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81\",\n      \"weight\": null\n    }\n  ],\n  \"name\": \"bedrock-team-a\",\n  \"strategy\": \"failover\",\n  \"fallback_to_managed\": false\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "members": [
    [
      "credential_id": "6d2a9f4c-3b1e-4d7a-8c5f-9e0b2a4c6d81",
      "weight": 
    ]
  ],
  "name": "bedrock-team-a",
  "strategy": "failover",
  "fallback_to_managed": false
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api-gateway.merge.dev/v1/key-sets/key_set_id")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```