> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.runtype.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.runtype.com/_mcp/server.

# Delegate a task to the Runtype operator agent

POST https://api.runtype.com/v1/delegate-tasks
Content-Type: application/json

Start a task the operator agent works through in your organization: it reads and changes agents, flows, records, tools, evals and surfaces with the same authority as the caller. With `waitSeconds` the response waits up to that long for the task to finish or to stop on a question (`input_required`) before answering; otherwise it returns the queued task at once. An identical delegation from the same caller that is still running is returned again (200, `deduplicated: true`) instead of starting a second one. API keys need `DELEGATE_TASKS:WRITE`.

Reference: https://docs.runtype.com/api-reference/runtype-api/delegate-tasks/delegate-a-task-to-the-runtype-operator-agent

## Authentication

- `Authorization` header (bearer token, required) — API key or Clerk session token

## Servers

- `https://api.runtype.com` (Production, default)
- `https://api.runtype-staging.com` (Staging)

## Request

### Body (application/json)

This endpoint expects an object.

- `instruction` (string, required)
- `allowDestructive` (boolean, optional)
- `clientName` (string, optional)
- `clientVersion` (string, optional)
- `context` (any, optional)
- `maxToolCalls` (integer, optional)
- `waitSeconds` (integer, optional)

## Response

### 200

The still-running task this request duplicated

- `apiKeyId` (string, required, nullable)
- `clientName` (string, required, nullable)
- `clientVersion` (string, required, nullable)
- `completedAt` (string, required, nullable)
- `createdAt` (string, required)
- `error` (string, required, nullable)
- `id` (string, required)
- `instruction` (string, required)
- `lastEventSeq` (integer, required)
- `modelRoundCount` (integer, required)
- `organizationId` (string, required)
- `question` (string, required, nullable)
- `result` (V1DelegateTasksPostResponsesContentApplicationJsonSchemaResult, required, nullable)
- `startedAt` (string, required, nullable)
- `status` (enum, required)
  - Allowed values: `queued`, `running`, `input_required`, `completed`, `failed`, `cancelled`
- `summary` (string, required, nullable)
- `toolCallCount` (integer, required)
- `totalCost` (double, required, nullable)
- `touchedEntities` (list of V1DelegateTasksPostResponsesContentApplicationJsonSchemaTouchedEntitiesItems, required)
- `updatedAt` (string, required)
- `userId` (string, required)
- `context` (any, optional)
- `deduplicated` (boolean, optional) — True when an identical delegation from the same caller was still running, so that task was returned instead of starting another.

### 201

The task

- `apiKeyId` (string, required, nullable)
- `clientName` (string, required, nullable)
- `clientVersion` (string, required, nullable)
- `completedAt` (string, required, nullable)
- `createdAt` (string, required)
- `error` (string, required, nullable)
- `id` (string, required)
- `instruction` (string, required)
- `lastEventSeq` (integer, required)
- `modelRoundCount` (integer, required)
- `organizationId` (string, required)
- `question` (string, required, nullable)
- `result` (V1DelegateTasksPostResponsesContentApplicationJsonSchemaResult, required, nullable)
- `startedAt` (string, required, nullable)
- `status` (enum, required)
  - Allowed values: `queued`, `running`, `input_required`, `completed`, `failed`, `cancelled`
- `summary` (string, required, nullable)
- `toolCallCount` (integer, required)
- `totalCost` (double, required, nullable)
- `touchedEntities` (list of V1DelegateTasksPostResponsesContentApplicationJsonSchemaTouchedEntitiesItems, required)
- `updatedAt` (string, required)
- `userId` (string, required)
- `context` (any, optional)
- `deduplicated` (boolean, optional) — True when an identical delegation from the same caller was still running, so that task was returned instead of starting another.

## Errors

### 400 Bad Request Error

Invalid input

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 401 Unauthorized Error

Unauthorized

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 403 Forbidden Error

Missing API key scope

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 404 Not Found Error

Feature disabled, or no such task in this organization

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 413 Content Too Large Error

`context` is larger than 16 KB of JSON

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 503 Service Unavailable Error

The operator agent is not available on this deployment

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

## Types

### V1DelegateTasksPostResponsesContentApplicationJsonSchemaResult

- `links` (list of V1DelegateTasksPostResponsesContentApplicationJsonSchemaResultLinksItems, required)
- `modelRoundCount` (integer, required)
- `summary` (string, required)
- `toolCallCount` (integer, required)
- `touchedEntities` (list of V1DelegateTasksPostResponsesContentApplicationJsonSchemaResultTouchedEntitiesItems, required)
- `totalCost` (double, optional)
- `warnings` (list of string, optional)

### V1DelegateTasksPostResponsesContentApplicationJsonSchemaTouchedEntitiesItems

- `action` (enum, required)
  - Allowed values: `created`, `updated`, `deleted`, `executed`, `read`
- `id` (string, required)
- `kind` (string, required)
- `name` (string, optional)

### ErrorDetailsItems

- `message` (string, required)
- `code` (string, optional) — Stable Runtype validation code (e.g. MISSING_REQUIRED_FIELD, INVALID_ENUM).
- `path` (string, optional) — Dotted JSON path to the offending field.
- `suggestion` (string, optional) — Actionable hint (allowed values, accepted range, …).

### V1DelegateTasksPostResponsesContentApplicationJsonSchemaResultLinksItems

- `label` (string, required)
- `url` (string, required)

### V1DelegateTasksPostResponsesContentApplicationJsonSchemaResultTouchedEntitiesItems

- `action` (enum, required)
  - Allowed values: `created`, `updated`, `deleted`, `executed`, `read`
- `id` (string, required)
- `kind` (string, required)
- `name` (string, optional)

## Examples

### Example 1

**Request**

```json
{
  "instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment."
}
```

**Response**

```json
{
  "apiKeyId": "key_01HQ8ZTXN2F3G4H5J6K7L8M9P0",
  "clientName": "runtype-cli",
  "clientVersion": "2.4.1",
  "completedAt": "2024-11-15T10:35:42Z",
  "createdAt": "2024-11-15T10:34:58Z",
  "error": null,
  "id": "task_01HQ8ZTXN2F3G4H5J6K7L8M9P1",
  "instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.",
  "lastEventSeq": 14,
  "modelRoundCount": 5,
  "organizationId": "org_01HQ8ZTXN2F3G4H5J6K7L8M9P2",
  "question": null,
  "result": {
    "links": [
      {
        "label": "Customer Support Agent",
        "url": "https://app.runtype.com/agents/agt_01HQ8ZTXN2F3G4H5J6K7L8M9P3"
      }
    ],
    "modelRoundCount": 5,
    "summary": "Created a customer support agent with an escalation flow, registered a ticket lookup tool connected to the helpdesk API, and enabled the live chat surface for the production environment.",
    "toolCallCount": 8,
    "touchedEntities": [
      {
        "action": "created",
        "id": "agt_01HQ8ZTXN2F3G4H5J6K7L8M9P3",
        "kind": "agent",
        "name": "Customer Support Agent"
      },
      {
        "action": "created",
        "id": "flow_01HQ8ZTXN2F3G4H5J6K7L8M9P4",
        "kind": "flow",
        "name": "Escalation Flow"
      },
      {
        "action": "created",
        "id": "tool_01HQ8ZTXN2F3G4H5J6K7L8M9P5",
        "kind": "tool",
        "name": "Ticket Lookup"
      }
    ],
    "totalCost": 0.0342,
    "warnings": [
      "Live chat surface requires manual DNS verification before going fully live."
    ]
  },
  "startedAt": "2024-11-15T10:35:01Z",
  "status": "completed",
  "summary": "Successfully created customer support agent, escalation flow, ticket lookup tool, and enabled live chat surface.",
  "toolCallCount": 8,
  "totalCost": 0.0342,
  "touchedEntities": [
    {
      "action": "created",
      "id": "agt_01HQ8ZTXN2F3G4H5J6K7L8M9P3",
      "kind": "agent",
      "name": "Customer Support Agent"
    },
    {
      "action": "created",
      "id": "flow_01HQ8ZTXN2F3G4H5J6K7L8M9P4",
      "kind": "flow",
      "name": "Escalation Flow"
    },
    {
      "action": "created",
      "id": "tool_01HQ8ZTXN2F3G4H5J6K7L8M9P5",
      "kind": "tool",
      "name": "Ticket Lookup"
    }
  ],
  "updatedAt": "2024-11-15T10:35:42Z",
  "userId": "user_01HQ8ZTXN2F3G4H5J6K7L8M9P6",
  "deduplicated": false
}
```

**SDK Code**

```python
import requests

url = "https://api.runtype.com/v1/delegate-tasks"

payload = { "instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment." }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.runtype.com/v1/delegate-tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"instruction":"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment."}'
};

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.runtype.com/v1/delegate-tasks"

	payload := strings.NewReader("{\n  \"instruction\": \"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.\"\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
require 'uri'
require 'net/http'

url = URI("https://api.runtype.com/v1/delegate-tasks")

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  \"instruction\": \"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.\"\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.post("https://api.runtype.com/v1/delegate-tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"instruction\": \"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.runtype.com/v1/delegate-tasks', [
  'body' => '{
  "instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment."
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.runtype.com/v1/delegate-tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"instruction\": \"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment."] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.runtype.com/v1/delegate-tasks")! 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()
```

### Example 2

**Request**

```json
{
  "instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment."
}
```

**Response**

```json
{
  "apiKeyId": "key_01HQ8ZTXN2F3G4H5J6K7L8M9P0",
  "clientName": "runtype-cli",
  "clientVersion": "2.4.1",
  "completedAt": "2024-11-15T10:35:42Z",
  "createdAt": "2024-11-15T10:34:58Z",
  "error": null,
  "id": "task_01HQ8ZTXN2F3G4H5J6K7L8M9P1",
  "instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.",
  "lastEventSeq": 14,
  "modelRoundCount": 5,
  "organizationId": "org_01HQ8ZTXN2F3G4H5J6K7L8M9P2",
  "question": null,
  "result": {
    "links": [
      {
        "label": "Customer Support Agent",
        "url": "https://app.runtype.com/agents/agt_01HQ8ZTXN2F3G4H5J6K7L8M9P3"
      }
    ],
    "modelRoundCount": 5,
    "summary": "Created a customer support agent with an escalation flow, registered a ticket lookup tool connected to the helpdesk API, and enabled the live chat surface for the production environment.",
    "toolCallCount": 8,
    "touchedEntities": [
      {
        "action": "created",
        "id": "agt_01HQ8ZTXN2F3G4H5J6K7L8M9P3",
        "kind": "agent",
        "name": "Customer Support Agent"
      },
      {
        "action": "created",
        "id": "flow_01HQ8ZTXN2F3G4H5J6K7L8M9P4",
        "kind": "flow",
        "name": "Escalation Flow"
      },
      {
        "action": "created",
        "id": "tool_01HQ8ZTXN2F3G4H5J6K7L8M9P5",
        "kind": "tool",
        "name": "Ticket Lookup"
      }
    ],
    "totalCost": 0.0342,
    "warnings": [
      "Live chat surface requires manual DNS verification before going fully live."
    ]
  },
  "startedAt": "2024-11-15T10:35:01Z",
  "status": "completed",
  "summary": "Successfully created customer support agent, escalation flow, ticket lookup tool, and enabled live chat surface.",
  "toolCallCount": 8,
  "totalCost": 0.0342,
  "touchedEntities": [
    {
      "action": "created",
      "id": "agt_01HQ8ZTXN2F3G4H5J6K7L8M9P3",
      "kind": "agent",
      "name": "Customer Support Agent"
    },
    {
      "action": "created",
      "id": "flow_01HQ8ZTXN2F3G4H5J6K7L8M9P4",
      "kind": "flow",
      "name": "Escalation Flow"
    },
    {
      "action": "created",
      "id": "tool_01HQ8ZTXN2F3G4H5J6K7L8M9P5",
      "kind": "tool",
      "name": "Ticket Lookup"
    }
  ],
  "updatedAt": "2024-11-15T10:35:42Z",
  "userId": "user_01HQ8ZTXN2F3G4H5J6K7L8M9P6",
  "deduplicated": false
}
```

**SDK Code**

```python
import requests

url = "https://api.runtype.com/v1/delegate-tasks"

payload = { "instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment." }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.runtype.com/v1/delegate-tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"instruction":"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment."}'
};

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.runtype.com/v1/delegate-tasks"

	payload := strings.NewReader("{\n  \"instruction\": \"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.\"\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
require 'uri'
require 'net/http'

url = URI("https://api.runtype.com/v1/delegate-tasks")

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  \"instruction\": \"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.\"\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.post("https://api.runtype.com/v1/delegate-tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"instruction\": \"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.runtype.com/v1/delegate-tasks', [
  'body' => '{
  "instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment."
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.runtype.com/v1/delegate-tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"instruction\": \"Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment.\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["instruction": "Create a new customer support agent with escalation flow, add a tool for ticket lookup, and enable the live chat surface for the production environment."] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.runtype.com/v1/delegate-tasks")! 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()
```