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

# Run Agent

POST https://api.conductorquantum.com/v0/coda/agents
Content-Type: application/json

Chat with the unified Coda AI agent to write, debug, and optimise quantum circuits or explain quantum computing concepts. Responses are streamed as server-sent events (SSE). Optional `team_id` bills an Enterprise team wallet. Personal tokens bill the personal wallet unless `team_id` is set. Team service-account keys always bill their team. A mismatched `team_id` returns 400. There is no fallback to the personal wallet. Response headers include `X-Run-Id`, `X-Thread-Id`, and `X-Team-Id` (when a team is billed). Settled cost is not in the SSE payload; look it up with the usage API.

Reference: https://docs.conductorquantum.com/api-reference/coda-api/agents/run

## Authentication

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

## Request

### Headers

- `x-api-path` (string, optional, nullable)

### Body (application/json)

This endpoint expects an AgentsRequest.

- `messages` (list of AgentsMessage, required) — Conversation messages
- `thread_id` (string, optional, nullable) — Thread ID for conversation continuity
- `team_id` (string, optional, nullable) — Optional Enterprise team wallet to bill. Personal tokens bill the personal wallet unless `team_id` is set. Team service-account keys always bill their team (omitting `team_id` does not switch to personal billing). A mismatched `team_id` returns 400. A short team wallet returns 402 with no fallback to the personal wallet.
- `code_mode` (enum, optional, default: inline) — 'inline' (default): the agent streams final code as fenced markdown tokens with the canonical framework language tag. 'file': the agent writes code to a virtual filesystem instead; written files are streamed back in a terminal 'files' SSE event.
  - Allowed values: `inline`, `file`
- `budget` (enum, optional, default: high) — Agent effort budget. 'low', 'medium', and 'high' (default) scale the model's thinking effort, max output tokens, step limit, and parallel research-subagent pool.
  - Allowed values: `low`, `medium`, `high`
- `fast` (boolean, optional, default: false, deprecated) — Deprecated compatibility flag; ignored by the unified agent
- `mode` (enum, optional, default: agent, deprecated) — 'agent' is the unified Coda agent. 'build' and 'learn' are deprecated aliases.
  - Allowed values: `agent`, `build`, `learn`

## Response

### 200

Server-sent event stream. Each event is a JSON object with a `type` field. With `code_mode: "inline"` (default), final code is streamed in `token` events as a complete fenced markdown block with the canonical framework language tag, followed by `completed`. With `code_mode: "file"` the agent writes code to a virtual filesystem instead, and a terminal `files` event carries `data.files` mapping each file path to its contents.

- `any`

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### AgentsMessage

A message in the conversation.

- `role` (enum, required) — Message role
  - Allowed values: `user`, `assistant`
- `content` (string, required) — Message content

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `input` (any, optional)
- `ctx` (ValidationErrorCtx, optional)

### ValidationErrorLocItems

### ValidationErrorCtx

## Examples

**Request**

```json
{
  "body": {
    "messages": [
      {
        "role": "user",
        "content": "Create a Bell state circuit in OpenQASM"
      }
    ],
    "mode": "agent",
    "code_mode": "inline",
    "budget": "high"
  }
}
```

**SDK Code**

```python conductorquantum
from conductorquantum import ConductorQuantum

client = ConductorQuantum(token="<token>")
for event in client.coda.agents.run(
    messages=[{"role": "user", "content": "Create a Bell state circuit in OpenQASM"}],
    budget="high",
):
    print(event)
```

```javascript
const url = 'https://api.conductorquantum.com/v0/coda/agents';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"body":{"messages":[{"role":"user","content":"Create a Bell state circuit in OpenQASM"}],"mode":"agent","code_mode":"inline","budget":"high"}}'
};

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.conductorquantum.com/v0/coda/agents"

	payload := strings.NewReader("{\n  \"body\": {\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Create a Bell state circuit in OpenQASM\"\n      }\n    ],\n    \"mode\": \"agent\",\n    \"code_mode\": \"inline\",\n    \"budget\": \"high\"\n  }\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.conductorquantum.com/v0/coda/agents")

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  \"body\": {\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Create a Bell state circuit in OpenQASM\"\n      }\n    ],\n    \"mode\": \"agent\",\n    \"code_mode\": \"inline\",\n    \"budget\": \"high\"\n  }\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.conductorquantum.com/v0/coda/agents")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"body\": {\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Create a Bell state circuit in OpenQASM\"\n      }\n    ],\n    \"mode\": \"agent\",\n    \"code_mode\": \"inline\",\n    \"budget\": \"high\"\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.conductorquantum.com/v0/coda/agents', [
  'body' => '{
  "body": {
    "messages": [
      {
        "role": "user",
        "content": "Create a Bell state circuit in OpenQASM"
      }
    ],
    "mode": "agent",
    "code_mode": "inline",
    "budget": "high"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.conductorquantum.com/v0/coda/agents");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"body\": {\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Create a Bell state circuit in OpenQASM\"\n      }\n    ],\n    \"mode\": \"agent\",\n    \"code_mode\": \"inline\",\n    \"budget\": \"high\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["body": [
    "messages": [
      [
        "role": "user",
        "content": "Create a Bell state circuit in OpenQASM"
      ]
    ],
    "mode": "agent",
    "code_mode": "inline",
    "budget": "high"
  ]] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.conductorquantum.com/v0/coda/agents")! 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()
```