# Link a tool to an agent

> POST https://api.nabrah.ai/api/ext/tool/link

Group: Tools. Page: https://www.nabrah.ai/en/docs/api-reference/tools/link-a-tool-to-an-agent

Link a tool to an agent so the agent can call that tool during conversations. The relationship is many-to-many: a tool can be linked to many agents and an agent can have many tools. The response returns a link record whose id is the link_id — keep it, since it is how you later remove the link via DELETE /api/ext/tool/unlink/{link_id}. Authenticated with your API key.

## Request fields

- **Link target**: tool_id is the tool to attach (from GET /api/ext/tool or the create-tool response). agent_id is the agent to attach it to (from GET /api/ext/agent). Both must belong to the project the API key is scoped to. Fields: `tool_id`, `agent_id`.

## End-to-end flow

Typical lifecycle for making a tool callable by an agent.

1) Create a tool with POST /api/ext/tool (or pick one from GET /api/ext/tool). 2) Create or choose an agent with GET /api/ext/agent. 3) Link them here — the response id is the link_id. 4) Later, detach with DELETE /api/ext/tool/unlink/{link_id}.

## Response fields

- **Link record**: id is the link_id used to unlink. tool_id and agent_id echo the linked pair, project_id is the owning project, and created_at / updated_at are the link timestamps. Fields: `id`, `tool_id`, `agent_id`, `project_id`, `created_at`, `updated_at`.

## Authorization

- `X-API-Key` (string, header, required): your workspace API key.

## Body (application/json)

### Example: Link tool to agent

```json
{
  "tool_id": "00000000-0000-4000-8000-000000000000",
  "agent_id": "00000000-0000-4000-8000-000000000000"
}
```

## Response

### 200 Successful Response

Content type: `application/json`

```json
{
  "id": "00000000-0000-4000-8000-000000000000",
  "tool_id": "00000000-0000-4000-8000-000000000000",
  "agent_id": "00000000-0000-4000-8000-000000000000",
  "project_id": "00000000-0000-4000-8000-000000000000",
  "created_at": "2026-01-15T12:00:00.000Z",
  "updated_at": "2026-01-15T12:00:00.000Z"
}
```

### 422 Validation Error

Content type: `application/json`

```json
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Request examples

### cURL

```bash
curl --request POST \
  --url 'https://api.nabrah.ai/api/ext/tool/link' \
  --header 'X-API-Key: <your-api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "tool_id": "00000000-0000-4000-8000-000000000000",
  "agent_id": "00000000-0000-4000-8000-000000000000"
}'
```

### Python

```python
import requests

url = "https://api.nabrah.ai/api/ext/tool/link"
headers = {
    "X-API-Key": "<your-api-key>",
}
payload = {
    "tool_id": "00000000-0000-4000-8000-000000000000",
    "agent_id": "00000000-0000-4000-8000-000000000000"
}

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

### JavaScript

```javascript
const response = await fetch("https://api.nabrah.ai/api/ext/tool/link", {
  method: "POST",
  headers: {
    "X-API-Key": "<your-api-key>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "tool_id": "00000000-0000-4000-8000-000000000000",
    "agent_id": "00000000-0000-4000-8000-000000000000"
  }),
});

const data = await response.json();
console.log(data);
```

### Go

```go
package main

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

func main() {
	payload := strings.NewReader(`{
  "tool_id": "00000000-0000-4000-8000-000000000000",
  "agent_id": "00000000-0000-4000-8000-000000000000"
}`)

	req, _ := http.NewRequest("POST", "https://api.nabrah.ai/api/ext/tool/link", payload)
	req.Header.Set("X-API-Key", "<your-api-key>")
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	out, _ := io.ReadAll(res.Body)
	fmt.Println(string(out))
}
```
