---
docId: doc_a881a2cff60e48eaa304b7662b154583
title: Test a function
description: "Test the draft without changing the version agents use."
api:
  group: herramientas/funciones-personalizadas
  auth: bearer
  operations:
    - operationId: testFunction
      method: POST
      path: '/v1/tools/functions/{functionId}/test'
      postmanName: Test a function
---

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

# Test a function

Verify the draft, deploy it separately, and run it once with `input`. Agents keep using the published version.

## Example

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

```bash
curl -X POST "https://api.platic.ai/v1/tools/functions/$FUNCTION_ID/test" \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "input": { "taxId": "XAXX010101000" }
}'
```

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

```ts
await platic.tools.functions.test("fn_123", { input: { rfc: "XAXX010101000" } });
```

</Ways.Way>
</Ways>

<Note type="important">

HTTP calls really go out to the allowed domains. If the code creates or changes something in another system, the test does too.

</Note>

## Path parameters

| Parameter | Type | Description | Required |
|-----------|------|-------------|----------|
| `functionId` | string | Function ID | ✓ |

## Request body

```json
{
  "input": { "taxId": "XAXX010101000" }
}
```

| Field | Type | Description | Required |
|-------|------|-------------|----------|
| `input` | object | Sample input that meets the function's `input` schema. Up to 256 KB | — |
| `source` | string | Tests this code instead of the saved draft, without saving it | — |

Do not send `secrets`: the test uses the secrets bound to the function and answers `400` if the body has them.

## Response

An execution that fails inside the code is also a `200`, with `ok: false` and `error`.

```json
{
  "status": "success",
  "data": {
    "ok": true,
    "output": { "found": true, "name": "EXAMPLE COMPANY INC" },
    "durationMs": 412,
    "logs": ["info response {\"status\":200}"],
    "httpCalls": [
      { "method": "POST", "host": "api.example.com", "status": 200, "durationMs": 380 }
    ],
    "runId": "run_8d1f",
    "version": "draft",
    "nextStep": "It ran. The run is in the function's runs."
  }
}
```

## Response fields

| Field | Type | Description |
|-------|------|-------------|
| `ok` | boolean | Whether the execution finished well |
| `output` | any | What `run` returned, when `ok` is `true`. Up to 256 KB; the agent reads up to 16,000 characters |
| `error` | object | When `ok` is `false`: `code` and `message`. See [errors inside an execution](/api-reference/custom-functions#errors-inside-an-execution) |
| `durationMs` | integer | Duration of the execution |
| `logs` | string[] | What the code wrote with `log` |
| `httpCalls` | array | Each call with `method`, `host`, `status` and `durationMs` |
| `runId` | string | Execution ID, which stays in the [executions](/api-reference/custom-functions/executions) with `trigger: "test"` |
| `version` | string | `"draft"` in a test |
| `nextStep` | string | Text in English that says what comes next. Do not program against its wording |

## Errors

| Status | `details.code` | When |
|--------|----------------|------|
| `400` | `INVALID_REQUEST` | The body fails validation or has `secrets`. `details.issues` has the list of problems |
| `403` | `FORBIDDEN` or `INSUFFICIENT_SCOPE` | The credential does not have write access to Integrations |
| `404` | `NOT_FOUND` | The function does not exist in this workspace |
| `422` | `VALIDATION_FAILED` | The code does not pass verification. `details.issues` has each problem |
| `429` | `LIMIT_REACHED` | The day's call or deployment limit was exceeded. `details.resetAt` says when it frees up |

## Notes

- Each test counts against the day's calls and deployments (50 deployments per day per workspace).
- If the response is `SECRET_MISSING`, `details.hint` says which secret is missing: bind it with [Bind a secret](/api-reference/custom-functions/bind-secret) and test again.
- `EGRESS_DENIED` means the code called a domain that is not in `allowedDomains`. Add it with [Update a function](/api-reference/custom-functions/update).
- To check the published version instead of the draft, use [Run a function](/api-reference/custom-functions/run).
