---
docId: doc_f68c68ecec764ee0a17ccca05478aede
title: Connect a file
description: Connects a file that already exists in the workspace to an agent. It applies immediately and doesn't create a version.
api:
  group: agentes/archivos
  auth: bearer
  operations:
    - operationId: attachFile
      method: PUT
      path: '/v1/agents/{agentId}/files/{fileId}'
      postmanName: Connect a file
---

<script>
  import { Ways } from '$lib/components';
</script>

# Connect a file

Connect an existing file so an agent can use it. Send `agentId` and `fileId` in the URL, with no body. **The connection applies immediately, without publishing**, and does not create a version.

## Example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
curl -X PUT https://api.platic.ai/v1/agents/$AGENT_ID/files/$FILE_ID \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
await platic.agents.files.connect("agent_123", "file_123");
```

</Ways.Way>
</Ways>

## Path parameters

| Parameter | Type | Description | Required |
|-----------|------|-------------|----------|
| `agentId` | string | Agent id | ✓ |
| `fileId` | string | File id | ✓ |

## Request body

No body.

## Response

`201 Created` with the new connection, or `200 OK` with the one that already existed, unchanged:

```json
{
  "status": "success",
  "data": {
    "agentId": "Lm4Rt8Wq2Zp6Yb1Nc3Vd",
    "fileId": "fH3kL9mQ2xR7",
    "state": "active",
    "attachedAt": "2026-11-01T12:30:00.000Z",
    "activateOnReady": false,
    "schedule": null
  }
}
```

`data` is the connection, with the fields from [List agent files](/api-reference/agents/files/list#connection-fields-link).

## Errors

| Status | `details.code` | When |
|--------|----------------|------|
| `403` | `RESOURCE_NOT_ACCESSIBLE` | Integrations is missing or you can't edit the agent. |
| `404` | `AGENT_NOT_FOUND` | The agent doesn't exist or belongs to another workspace. |
| `404` | `RESOURCE_NOT_ACCESSIBLE` | The file doesn't exist in this workspace. |
| `409` | `FILE_NOT_READY` | The file doesn't have content ready or is being deleted. |

The ones that apply to all operations are in [common errors](/api-reference/files#common-errors).

## Notes

- The file is shared with other agents; no copy is created. To create one already connected, use [Create a file](/api-reference/files/create) with `attachment.agentId`.
- It needs Integrations **and** being able to edit the agent.
- Connecting a file that is already connected answers `200` and doesn't change its state.
- In the [SDK](/sdk), you can connect it and leave it paused in a single call with `platic.agents.files.connect(agentId, fileId, { state: "paused" })`.
- For the agent to stop using it without losing the connection, use [Pause or schedule a file](/api-reference/agents/files/schedule). To remove it, [Disconnect a file](/api-reference/agents/files/disconnect).
- From an AI agent, the tool is [`connect_agent_file`](/mcp/tools#files).
