> This page is for Workforce.

> 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 access key

POST https://ah-api.merge.dev/api/v1/access-keys/
Content-Type: application/json

Creates a new access key. Can be scoped to specific tool packs and registered users. The new key's scope must be a subset of the parent key (the access key authenticating this request).

Reference: https://docs.merge.dev/merge-workforce/agent-handler/access-keys/access-keys-create

## Authentication

- `Authorization` header (bearer token, required) — Token-based authentication with required prefix "Bearer"

## Request

### Body (application/json)

This endpoint expects an AccessKeyCreateRequest.

- `name` (string, optional) — Human-readable label for the key. Auto-generated if omitted.
- `tool_pack_ids` (list of string, optional, nullable) — Tool packs this key can access. Must be a subset of the parent key's `tool_pack_ids`. Pass `null` for unrestricted access to all tool packs in the organization.
- `registered_user_ids` (list of string, optional, nullable) — Registered users this key can access. Must be a subset of the parent key's `registered_user_ids`. Pass `null` for unrestricted access to all registered users in the organization.
- `scopes` (list of string, optional) — Limits which actions this key can perform. Available scopes: `runtime:all` (MCP tool calls), `management:all` (resource management endpoints).
- `is_test` (boolean, optional, default: false) — If true, the key can only authenticate test registered users.
- `expires_at` (datetime, optional, nullable) — Expiration timestamp. Must be before the parent key's `expires_at`. Defaults to 90 days from now if omitted. Pass `null` explicitly for a key that never expires.
- `expires_in` (integer, optional) — Seconds until the key expires. Alternative to `expires_at`.

## Response

### 201

- `id` (string, required)
- `key` (string, required, nullable) — Raw secret value. Returned only on create or regenerate.
- `key_masked` (string, required) — Truncated form of the secret safe to display in UIs.
- `created_at` (datetime, required)
- `name` (string, optional) — Human-readable label for the key. Auto-generated if omitted.
- `tool_pack_ids` (list of string, optional, nullable) — Tool packs this key can access. Must be a subset of the parent key's `tool_pack_ids`. Pass `null` for unrestricted access to all tool packs in the organization.
- `registered_user_ids` (list of string, optional, nullable) — Registered users this key can access. Must be a subset of the parent key's `registered_user_ids`. Pass `null` for unrestricted access to all registered users in the organization.
- `scopes` (list of string, optional) — Limits which actions this key can perform. Available scopes: `runtime:all` (MCP tool calls), `management:all` (resource management endpoints).
- `is_test` (boolean, optional, default: false) — If true, the key can only authenticate test registered users.
- `expires_at` (datetime, optional, nullable) — Expiration timestamp. Must be before the parent key's `expires_at`. Defaults to 90 days from now if omitted. Pass `null` explicitly for a key that never expires.
- `expires_in` (integer, optional) — Seconds until the key expires. Alternative to `expires_at`.

## Examples

### Full access (application/json)

**Request**

```json
{
  "name": "long-lived",
  "expires_at": null
}
```

**Response**

```json
{
  "id": "3c90c3c0-6d46-4b50-8888-8dd25736052f",
  "key": "sk_live_lll999...",
  "key_masked": "sk_live_lll...9f8e",
  "created_at": "2026-04-29T12:00:00Z",
  "name": "long-lived",
  "tool_pack_ids": null,
  "registered_user_ids": null,
  "is_test": false,
  "expires_at": null
}
```

**SDK Code**

```python Full access (application/json)
import requests

url = "https://ah-api.merge.dev/api/v1/access-keys/"

payload = {
    "name": "long-lived",
    "expires_at": None
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Full access (application/json)
const url = 'https://ah-api.merge.dev/api/v1/access-keys/';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"long-lived","expires_at":null}'
};

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

```go Full access (application/json)
package main

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

func main() {

	url := "https://ah-api.merge.dev/api/v1/access-keys/"

	payload := strings.NewReader("{\n  \"name\": \"long-lived\",\n  \"expires_at\": null\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 Full access (application/json)
require 'uri'
require 'net/http'

url = URI("https://ah-api.merge.dev/api/v1/access-keys/")

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\": \"long-lived\",\n  \"expires_at\": null\n}"

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

```java Full access (application/json)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://ah-api.merge.dev/api/v1/access-keys/")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"long-lived\",\n  \"expires_at\": null\n}")
  .asString();
```

```php Full access (application/json)
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://ah-api.merge.dev/api/v1/access-keys/', [
  'body' => '{
  "name": "long-lived",
  "expires_at": null
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Full access (application/json)
using RestSharp;

var client = new RestClient("https://ah-api.merge.dev/api/v1/access-keys/");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"long-lived\",\n  \"expires_at\": null\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Full access (application/json)
import Foundation

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

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

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

### Scoped (application/json)

**Request**

```json
{
  "name": "support-bot",
  "tool_pack_ids": [
    "1d8b6f4a-1b3e-4f9b-9d3a-3a8e8b9c0d1f"
  ],
  "registered_user_ids": [
    "4f7b2a3d-9c1e-4a5b-8e2f-7d6c5b4a3e2d"
  ],
  "scopes": [
    "runtime:all"
  ],
  "expires_in": 3600
}
```

**Response**

```json
{
  "id": "3c90c3c0-6d46-4b50-8888-8dd25736052f",
  "key": "sk_live_lll999...",
  "key_masked": "sk_live_lll...9f8e",
  "created_at": "2026-04-29T12:00:00Z",
  "name": "long-lived",
  "tool_pack_ids": null,
  "registered_user_ids": null,
  "is_test": false,
  "expires_at": null
}
```

**SDK Code**

```python Scoped (application/json)
import requests

url = "https://ah-api.merge.dev/api/v1/access-keys/"

payload = {
    "name": "support-bot",
    "tool_pack_ids": ["1d8b6f4a-1b3e-4f9b-9d3a-3a8e8b9c0d1f"],
    "registered_user_ids": ["4f7b2a3d-9c1e-4a5b-8e2f-7d6c5b4a3e2d"],
    "scopes": ["runtime:all"],
    "expires_in": 3600
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Scoped (application/json)
const url = 'https://ah-api.merge.dev/api/v1/access-keys/';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"support-bot","tool_pack_ids":["1d8b6f4a-1b3e-4f9b-9d3a-3a8e8b9c0d1f"],"registered_user_ids":["4f7b2a3d-9c1e-4a5b-8e2f-7d6c5b4a3e2d"],"scopes":["runtime:all"],"expires_in":3600}'
};

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

```go Scoped (application/json)
package main

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

func main() {

	url := "https://ah-api.merge.dev/api/v1/access-keys/"

	payload := strings.NewReader("{\n  \"name\": \"support-bot\",\n  \"tool_pack_ids\": [\n    \"1d8b6f4a-1b3e-4f9b-9d3a-3a8e8b9c0d1f\"\n  ],\n  \"registered_user_ids\": [\n    \"4f7b2a3d-9c1e-4a5b-8e2f-7d6c5b4a3e2d\"\n  ],\n  \"scopes\": [\n    \"runtime:all\"\n  ],\n  \"expires_in\": 3600\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 Scoped (application/json)
require 'uri'
require 'net/http'

url = URI("https://ah-api.merge.dev/api/v1/access-keys/")

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\": \"support-bot\",\n  \"tool_pack_ids\": [\n    \"1d8b6f4a-1b3e-4f9b-9d3a-3a8e8b9c0d1f\"\n  ],\n  \"registered_user_ids\": [\n    \"4f7b2a3d-9c1e-4a5b-8e2f-7d6c5b4a3e2d\"\n  ],\n  \"scopes\": [\n    \"runtime:all\"\n  ],\n  \"expires_in\": 3600\n}"

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

```java Scoped (application/json)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://ah-api.merge.dev/api/v1/access-keys/")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"support-bot\",\n  \"tool_pack_ids\": [\n    \"1d8b6f4a-1b3e-4f9b-9d3a-3a8e8b9c0d1f\"\n  ],\n  \"registered_user_ids\": [\n    \"4f7b2a3d-9c1e-4a5b-8e2f-7d6c5b4a3e2d\"\n  ],\n  \"scopes\": [\n    \"runtime:all\"\n  ],\n  \"expires_in\": 3600\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://ah-api.merge.dev/api/v1/access-keys/', [
  'body' => '{
  "name": "support-bot",
  "tool_pack_ids": [
    "1d8b6f4a-1b3e-4f9b-9d3a-3a8e8b9c0d1f"
  ],
  "registered_user_ids": [
    "4f7b2a3d-9c1e-4a5b-8e2f-7d6c5b4a3e2d"
  ],
  "scopes": [
    "runtime:all"
  ],
  "expires_in": 3600
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Scoped (application/json)
using RestSharp;

var client = new RestClient("https://ah-api.merge.dev/api/v1/access-keys/");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"support-bot\",\n  \"tool_pack_ids\": [\n    \"1d8b6f4a-1b3e-4f9b-9d3a-3a8e8b9c0d1f\"\n  ],\n  \"registered_user_ids\": [\n    \"4f7b2a3d-9c1e-4a5b-8e2f-7d6c5b4a3e2d\"\n  ],\n  \"scopes\": [\n    \"runtime:all\"\n  ],\n  \"expires_in\": 3600\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Scoped (application/json)
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "support-bot",
  "tool_pack_ids": ["1d8b6f4a-1b3e-4f9b-9d3a-3a8e8b9c0d1f"],
  "registered_user_ids": ["4f7b2a3d-9c1e-4a5b-8e2f-7d6c5b4a3e2d"],
  "scopes": ["runtime:all"],
  "expires_in": 3600
] as [String : Any]

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

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