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

# Create an agent thread

POST https://api.middesk.com/v1/threads
Content-Type: application/json

Creates a new agent thread for running agent workflows

Reference: https://docs.middesk.com/api-reference/agents/threads/create-agent-thread

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (application/json)

This endpoint expects an object.

- `type` (string, required) — The agent type to use for this agent thread
- `business_id` (string, optional) — Business to use as context for the thread. Shorthand for context_type=business. Required unless context_type and context_id are provided.
- `context_type` (string, optional) — The type of context resource (e.g., "business")
- `context_id` (string, optional) — The ID of the context resource. Must be provided with context_type.

## Response

### 201

agent thread created with context_type and context_id

- `object` (string, required) — Object type identifier.
- `id` (string, required) — Unique identifier for the agent thread.
- `created_at` (datetime, required) — Timestamp when the agent thread was created.
- `updated_at` (datetime, required) — Timestamp when the agent thread was last updated.
- `status` (enum, required) — Current lifecycle status of the agent thread.
  - Allowed values: `running`, `completed`, `error`, `interrupted`
- `metadata` (map from string to any, optional, nullable) — Internal metadata associated with the agent thread.
- `requester` (map from string to any, optional, nullable) — Requester context associated with the agent thread.
- `steps` (list of AgentsStep, optional) — Execution steps emitted by the underlying agent state

## Errors

### 404 Create Agent Thread Request Not Found Error

agent type not found

- `errors` (list of ErrorResponseErrorsItem, required)

## Types

### AgentsStep

A step in an agent workflow execution timeline.

- `id` (string, required) — Unique identifier for the step.
- `run_id` (string, required) — Identifier of the agent run that produced the step.
- `type` (enum, required) — Category of step output.
  - Allowed values: `activity`, `output`, `interrupt`, `error`
- `name` (string, required) — Internal step name.
- `label` (string, required) — Human-readable step label.
- `status` (enum, required) — Current execution status for the step.
  - Allowed values: `running`, `completed`, `error`
- `started_at` (datetime, required) — Timestamp when the step started.
- `agent` (string, optional) — Agent identifier that generated this step.
- `parent_step_id` (string, optional, nullable) — Parent step identifier for nested steps.
- `completed_at` (datetime, optional, nullable) — Timestamp when the step completed.
- `steps` (list of AgentsStep, optional) — Nested child steps.
- `result` (AgentsStepResult, optional) — Structured result payload for the step.
- `artifacts` (list of AgentsArtifact, optional) — Artifacts produced by the step.

### ErrorResponseErrorsItem

- `message` (string, required)
- `parameter` (string, optional) — Request parameter associated with the error, when applicable

### AgentsStepResult

Structured result payload for the step.

- `resolution` (enum, optional) — How the interrupt was resolved. Present only on completed interrupt steps when an interrupt policy auto-approved or skipped the interrupt. Absent for manual resolutions.
  - Allowed values: `auto_approve`, `skip`

### AgentsArtifact

A structured artifact produced by an agent step.

- `title` (string, required) — Human-readable title for the artifact.
- `type` (string, required) — Artifact type identifier.
- `confidence` (string, optional, nullable) — Optional confidence label for artifact quality.
- `summary` (string, optional, nullable) — Optional summary of the artifact contents.
- `sources` (list of AgentsSource, optional) — Source references used to produce the artifact.

### AgentsSource

A source reference used by an agent artifact.

- `url` (string, required) — Canonical source URL.
- `source_name` (string, optional) — Human-readable source name.
- `source_tier` (string, optional) — Source quality or trust tier.
- `source_type` (string, optional) — Source category.

## Examples

**Request**

```json
{
  "type": "cip_orchestrator"
}
```

**Response**

```json
{
  "object": "thread",
  "id": "id",
  "created_at": "2024-01-15T09:30:00Z",
  "updated_at": "2024-01-15T09:30:00Z",
  "status": "running",
  "metadata": {
    "key": "value"
  },
  "requester": {
    "key": "value"
  },
  "steps": [
    {
      "id": "id",
      "run_id": "run_id",
      "type": "activity",
      "name": "name",
      "label": "label",
      "status": "running",
      "started_at": "2024-01-15T09:30:00Z",
      "agent": "agent",
      "parent_step_id": "parent_step_id",
      "completed_at": "2024-01-15T09:30:00Z",
      "artifacts": [
        {
          "title": "title",
          "type": "type"
        }
      ]
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "https://api.middesk.com/v1/threads"

payload = { "type": "cip_orchestrator" }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.middesk.com/v1/threads';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"type":"cip_orchestrator"}'
};

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.middesk.com/v1/threads"

	payload := strings.NewReader("{\n  \"type\": \"cip_orchestrator\"\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.middesk.com/v1/threads")

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  \"type\": \"cip_orchestrator\"\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.middesk.com/v1/threads")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"type\": \"cip_orchestrator\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.middesk.com/v1/threads', [
  'body' => '{
  "type": "cip_orchestrator"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.middesk.com/v1/threads");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"type\": \"cip_orchestrator\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["type": "cip_orchestrator"] as [String : Any]

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

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