# Sandbox.Services.Ai.Query.Run

## Overload 1

```csharp
System.Threading.Tasks.Task<Response> Run(System.Threading.CancellationToken cancellationToken = null)
```

Runs the query and any configured tools. After an interrupted tool turn, Run again on this
query to resume the retained submission without rerunning completed tools. Reaching MaxToolRounds
is terminal for this query; create a new query with a higher configured limit if needed.

### Parameters

- `cancellationToken` (`System.Threading.CancellationToken`), default `null`

### Returns

`System.Threading.Tasks.Task<Response>`

## Overload 2

```csharp
System.Threading.Tasks.Task<Response<T>> Run(System.Threading.CancellationToken cancellationToken = null)
```

Runs the query and deserializes its final JSON answer as T. Tool-enabled queries describe
the output schema in their instructions; other queries use the backend's strict output schema.
Check HasData before reading Data. Invalid final JSON leaves HasData false and preserves the text and usage.
Reaching MaxToolRounds is terminal for this query, just as for the untyped Run overload.

### Parameters

- `cancellationToken` (`System.Threading.CancellationToken`), default `null`

### Returns

`System.Threading.Tasks.Task<Response<T>>`

Declared in [Sandbox.Services.Ai.Query](/api/Sandbox.Services.Ai.Query).
Assembly: `Sandbox.Engine`.
