> To find and run AgentRouter tools, connect to https://mcp.agentrouter.to/. To search this documentation, use https://docs.agentrouter.to/_mcp/server. Append .md to a page URL for Markdown. For the documentation index, see https://docs.agentrouter.to/llms.txt.

# Invoke a tool

POST https://api.agentrouter.to/v1/invoke
Content-Type: application/json

Validates the input against the tool's schema, checks that `pricing_version` is still
current, reserves the maximum charge (bounded by `max_cost_usd` and your budgets) and
runs the tool. The server waits up to `wait_ms` (default and maximum 25 seconds); a run
that is still going returns `202` and keeps running server-side — poll
`GET /v1/runs/{run_id}` instead of invoking again.

Send an `Idempotency-Key` header (or `idempotency_key`) to make retries safe: the same
key with the same request returns the original run with `replayed: true` and
`billing.charge_is_new: false`; the same key with a different request is rejected.

Requests rejected before a run is created (invalid input, stale `pricing_version`,
unknown tool) execute nothing and charge nothing. Runs blocked by balance, budgets or
limits are recorded with status `BLOCKED` and are not charged.

Reference: https://docs.agentrouter.to/api-reference/agent-router-api/runs/invoke

## Authentication

- `Authorization` header (bearer token, required) — An AgentRouter API key or an OAuth access token issued to an MCP host or the CLI.

## Request

### Headers

- `Idempotency-Key` (string, optional) — Client-chosen key (at most 200 characters) that makes retries return the original run.

### Body (application/json)

This endpoint expects an InvokeRequest.

- `tool_id` (string, required)
- `pricing_version` (string, required) — From describe. A changed price is refused (PRICING_CHANGED) instead of charged.
- `input` (InvokeRequestInput, optional) — Matches the tool's input_schema (an object or an array).
- `tool_version` (string, optional) — Optional pin; refused with TOOL_VERSION_CHANGED if the tool changed.
- `max_cost_usd` (string, optional) — Most you allow this call to cost. Default 0.50, lowered by budgets' per-call maximums.
- `session_id` (string, optional) — Groups runs of one agent task; session budgets apply.
- `idempotency_key` (string, optional) — Same as the Idempotency-Key header.
- `wait_ms` (integer, optional) — How long the request waits before returning 202.

## Response

### 200

The run finished (COMPLETED, FAILED, STOPPED or TIMED_OUT). Charges follow `billing.reason`.

- `object` (any, required)
- `run_id` (string, required)
- `status` (enum, required)
  - Allowed values: `READY`, `RUNNING`, `STOPPING`, `COMPLETED`, `FAILED`, `BLOCKED`, `STOPPED`, `TIMED_OUT`
- `tool_id` (string, required)
- `tool_version` (string, required)
- `provider` (string, required)
- `input` (any, required) — The submitted tool input
- `session_id` (string, required, nullable)
- `caller` (RunCaller, required)
- `channel` (enum, required)
  - Allowed values: `http`, `cli`, `mcp`, `web`
- `created_at` (string, required, nullable)
- `started_at` (string, required, nullable)
- `completed_at` (string, required, nullable)
- `latency_ms` (integer, required, nullable)
- `replayed` (boolean, required) — True when an idempotency key returned an existing run.
- `stoppable` (boolean, required)
- `provider_response` (RunProviderResponse, required)
- `error` (RunError, required, nullable)
- `billing` (RunBilling, required)
- `result` (RunResult, required)
- `next_cursor` (string, required, nullable) — Pass back as the tool's cursor input for the next page (a new billed call).
- `hints` (list of Hint, required)
- `output` (any, required) — The provider's output exactly as returned

### 202

Accepted and still running on the server. Poll the run; do not invoke again.

- `object` (any, required)
- `run_id` (string, required)
- `status` (enum, required)
  - Allowed values: `READY`, `RUNNING`, `STOPPING`, `COMPLETED`, `FAILED`, `BLOCKED`, `STOPPED`, `TIMED_OUT`
- `tool_id` (string, required)
- `tool_version` (string, required)
- `provider` (string, required)
- `input` (any, required) — The submitted tool input
- `session_id` (string, required, nullable)
- `caller` (RunCaller, required)
- `channel` (enum, required)
  - Allowed values: `http`, `cli`, `mcp`, `web`
- `created_at` (string, required, nullable)
- `started_at` (string, required, nullable)
- `completed_at` (string, required, nullable)
- `latency_ms` (integer, required, nullable)
- `replayed` (boolean, required) — True when an idempotency key returned an existing run.
- `stoppable` (boolean, required)
- `provider_response` (RunProviderResponse, required)
- `error` (RunError, required, nullable)
- `billing` (RunBilling, required)
- `result` (RunResult, required)
- `next_cursor` (string, required, nullable) — Pass back as the tool's cursor input for the next page (a new billed call).
- `hints` (list of Hint, required)
- `output` (any, required) — The provider's output exactly as returned

## Errors

### 400 Bad Request Error

Invalid request (for example INVALID_REQUEST, INPUT_INVALID, PRICING_VERSION_REQUIRED, PRICE_NOT_CLIENT_SETTABLE). Nothing was executed.

- `error` (ErrorError, required)
- `run` (Run, optional) — The receipt for one invocation. Run status, provider outcome and billing are separate facts.

### 401 Unauthorized Error

Missing or invalid credential (UNAUTHENTICATED, INVALID_CREDENTIAL)

- `error` (ErrorError, required)
- `run` (Run, optional) — The receipt for one invocation. Run status, provider outcome and billing are separate facts.

### 402 Payment Required Error

Blocked before execution for insufficient balance (`error.code` INSUFFICIENT_BALANCE). Not charged.

- `object` (any, required)
- `run_id` (string, required)
- `status` (enum, required)
  - Allowed values: `READY`, `RUNNING`, `STOPPING`, `COMPLETED`, `FAILED`, `BLOCKED`, `STOPPED`, `TIMED_OUT`
- `tool_id` (string, required)
- `tool_version` (string, required)
- `provider` (string, required)
- `input` (any, required) — The submitted tool input
- `session_id` (string, required, nullable)
- `caller` (RunCaller, required)
- `channel` (enum, required)
  - Allowed values: `http`, `cli`, `mcp`, `web`
- `created_at` (string, required, nullable)
- `started_at` (string, required, nullable)
- `completed_at` (string, required, nullable)
- `latency_ms` (integer, required, nullable)
- `replayed` (boolean, required) — True when an idempotency key returned an existing run.
- `stoppable` (boolean, required)
- `provider_response` (RunProviderResponse, required)
- `error` (RunError, required, nullable)
- `billing` (RunBilling, required)
- `result` (RunResult, required)
- `next_cursor` (string, required, nullable) — Pass back as the tool's cursor input for the next page (a new billed call).
- `hints` (list of Hint, required)
- `output` (any, required) — The provider's output exactly as returned

### 403 Forbidden Error

The credential lacks a scope (INSUFFICIENT_SCOPE)

- `error` (ErrorError, required)
- `run` (Run, optional) — The receipt for one invocation. Run status, provider outcome and billing are separate facts.

### 404 Not Found Error

Not found for this account (TOOL_NOT_FOUND, RUN_NOT_FOUND, NO_RESULT, ...)

- `error` (ErrorError, required)
- `run` (Run, optional) — The receipt for one invocation. Run status, provider outcome and billing are separate facts.

### 409 Conflict Error

Either a recorded run that was blocked before execution (budget, max_cost_usd, free-call quotas, promotion limits; body is the Run), or a request refused before any run exists (PRICING_CHANGED, TOOL_VERSION_CHANGED, TOOL_NOT_ENABLED, PRICE_UNAVAILABLE, IDEMPOTENCY_KEY_CONFLICT; body is an Error). Nothing is charged.

- `InvokeRequestConflictError`
  - Run: Run
  - Error: Error

## Types

### InvokeRequestInput

Matches the tool's input_schema (an object or an array).

- map from string to any
- list of any

### RunCaller

- `type` (enum, required)
  - Allowed values: `api_key`, `oauth`, `session`
- `name` (string, required)

### RunProviderResponse

- `http_status` (integer, required, nullable)
- `outcome` (enum, required)
  - Allowed values: `success`, `empty`, `provider_error`, `pending`
- `status` (string, required, nullable)
- `request_id` (string, required, nullable)
- `task_id` (string, required, nullable)

### RunError

- `code` (string, required)
- `message` (string, required)
- `origin` (enum, required)
  - Allowed values: `provider`, `platform`, `client`
- `retryable` (boolean, required, nullable)
- `details` (RunErrorDetails, optional, nullable) — Sanitized provider error evidence. Absent for old runs and errors without an upstream response.

### RunBilling

- `status` (enum, required)
  - Allowed values: `none`, `reserved`, `settled`, `refunded_partial`, `refunded_full`
- `reason` (enum, required) — Why the charge is what it is. A zero charge always carries a reason.
  - Allowed values: `charged`, `charged_capped`, `free_promotion`, `zero_base`, `waived_provider_error`, `waived_platform_error`, `waived_empty_result`, `waived_stopped`, `waived_timeout`, `waived_unknown_cost`, `blocked_before_execution`
- `currency` (any, required)
- `pricing_version` (string, required)
- `price_multiplier` (string, required, nullable)
- `promotion_id` (string, required, nullable)
- `max_cost_usd` (string, required) — Exact USD amount as a decimal string.
- `reserved_usd` (string, required) — Exact USD amount as a decimal string.
- `base_charge_usd` (string, required, nullable) — Price before the multiplier.
- `customer_charge_usd` (string, required) — Exact USD amount as a decimal string.
- `customer_refund_usd` (string, required) — Exact USD amount as a decimal string.
- `net_charge_usd` (string, required) — Exact USD amount as a decimal string.
- `charge_is_new` (boolean, required) — False on an idempotent replay; nothing new was charged.
- `usage` (RunBillingUsage, required, nullable)

### RunResult

- `available` (boolean, required)
- `expired` (boolean, required) — True when a previously stored result has expired or is no longer present.
- `bytes` (integer, required, nullable)
- `expires_at` (string, required, nullable)
- `url` (string, required, nullable) — GET this to download the stored output; it never re-runs the tool.
- `inline` (boolean, required) — False when the output is too large to include; download it from url.

### Hint

- `code` (string, required) — Machine-readable next step, e.g. POLL_RUN, DESCRIBE_TOOL, TOP_UP, NEXT_PAGE.
- `message` (string, required)
- `params` (map from string to any, optional)

### ErrorError

- `code` (string, required)
- `message` (string, required)
- `hints` (list of Hint, required)
- `details` (map from string to any, required)

### Run

The receipt for one invocation. Run status, provider outcome and billing are separate facts.

- `object` (any, required)
- `run_id` (string, required)
- `status` (enum, required)
  - Allowed values: `READY`, `RUNNING`, `STOPPING`, `COMPLETED`, `FAILED`, `BLOCKED`, `STOPPED`, `TIMED_OUT`
- `tool_id` (string, required)
- `tool_version` (string, required)
- `provider` (string, required)
- `input` (any, required) — The submitted tool input
- `session_id` (string, required, nullable)
- `caller` (RunCaller, required)
- `channel` (enum, required)
  - Allowed values: `http`, `cli`, `mcp`, `web`
- `created_at` (string, required, nullable)
- `started_at` (string, required, nullable)
- `completed_at` (string, required, nullable)
- `latency_ms` (integer, required, nullable)
- `replayed` (boolean, required) — True when an idempotency key returned an existing run.
- `stoppable` (boolean, required)
- `provider_response` (RunProviderResponse, required)
- `error` (RunError, required, nullable)
- `billing` (RunBilling, required)
- `result` (RunResult, required)
- `next_cursor` (string, required, nullable) — Pass back as the tool's cursor input for the next page (a new billed call).
- `hints` (list of Hint, required)
- `output` (any, required) — The provider's output exactly as returned

### Error

- `error` (ErrorError, required)
- `run` (Run, optional) — The receipt for one invocation. Run status, provider outcome and billing are separate facts.

### RunErrorDetails

Sanitized provider error evidence. Absent for old runs and errors without an upstream response.

- `body` (string, required) — Provider response JSON text with credentials and internal pricing fields redacted; non-JSON bodies are omitted. Limited to 20000 characters.
- `truncated` (boolean, required) — True when only a prefix of the sanitized error was retained.

### RunBillingUsage

- `unit` (string, required)
- `quantity` (string, required, nullable)
- `status` (enum, required)
  - Allowed values: `known`, `none`, `unknown`

## Examples

### Runs_invoke_example

**Request**

```json
{
  "tool_id": "anyapi.twitter.search",
  "pricing_version": "pv_anyapi.twitter.search_2026-11-06_1",
  "input": {
    "limit": 10,
    "query": "from:AnthropicAI"
  },
  "max_cost_usd": "0.02"
}
```

**Response**

```json
{
  "object": null,
  "run_id": "string",
  "status": "READY",
  "tool_id": "string",
  "tool_version": "string",
  "provider": "string",
  "input": null,
  "session_id": "string",
  "caller": {
    "type": "api_key",
    "name": "string"
  },
  "channel": "http",
  "created_at": "string",
  "started_at": "string",
  "completed_at": "string",
  "latency_ms": 1,
  "replayed": true,
  "stoppable": true,
  "provider_response": {
    "http_status": 1,
    "outcome": "success",
    "status": "string",
    "request_id": "string",
    "task_id": "string"
  },
  "error": {
    "code": "string",
    "message": "string",
    "origin": "provider",
    "retryable": true,
    "details": {
      "body": "string",
      "truncated": true
    }
  },
  "billing": {
    "status": "none",
    "reason": "charged",
    "currency": null,
    "pricing_version": "string",
    "price_multiplier": "string",
    "promotion_id": "string",
    "max_cost_usd": "0.0035",
    "reserved_usd": "0.0035",
    "base_charge_usd": "string",
    "customer_charge_usd": "0.0035",
    "customer_refund_usd": "0.0035",
    "net_charge_usd": "0.0035",
    "charge_is_new": true,
    "usage": {
      "unit": "string",
      "quantity": "string",
      "status": "known"
    }
  },
  "result": {
    "available": true,
    "expired": true,
    "bytes": 1,
    "expires_at": "string",
    "url": "string",
    "inline": true
  },
  "next_cursor": "string",
  "hints": [
    {
      "code": "string",
      "message": "string",
      "params": {}
    }
  ],
  "output": null
}
```

**SDK Code**

```python Runs_invoke_example
import requests

url = "https://api.agentrouter.to/v1/invoke"

payload = {
    "tool_id": "anyapi.twitter.search",
    "pricing_version": "pv_anyapi.twitter.search_2026-11-06_1",
    "input": {
        "limit": 10,
        "query": "from:AnthropicAI"
    },
    "max_cost_usd": "0.02"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Runs_invoke_example
const url = 'https://api.agentrouter.to/v1/invoke';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"tool_id":"anyapi.twitter.search","pricing_version":"pv_anyapi.twitter.search_2026-11-06_1","input":{"limit":10,"query":"from:AnthropicAI"},"max_cost_usd":"0.02"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Runs_invoke_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.agentrouter.to/v1/invoke"

	payload := strings.NewReader("{\n  \"tool_id\": \"anyapi.twitter.search\",\n  \"pricing_version\": \"pv_anyapi.twitter.search_2026-11-06_1\",\n  \"input\": {\n    \"limit\": 10,\n    \"query\": \"from:AnthropicAI\"\n  },\n  \"max_cost_usd\": \"0.02\"\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 Runs_invoke_example
require 'uri'
require 'net/http'

url = URI("https://api.agentrouter.to/v1/invoke")

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  \"tool_id\": \"anyapi.twitter.search\",\n  \"pricing_version\": \"pv_anyapi.twitter.search_2026-11-06_1\",\n  \"input\": {\n    \"limit\": 10,\n    \"query\": \"from:AnthropicAI\"\n  },\n  \"max_cost_usd\": \"0.02\"\n}"

response = http.request(request)
puts response.read_body
```

```java Runs_invoke_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.agentrouter.to/v1/invoke")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"tool_id\": \"anyapi.twitter.search\",\n  \"pricing_version\": \"pv_anyapi.twitter.search_2026-11-06_1\",\n  \"input\": {\n    \"limit\": 10,\n    \"query\": \"from:AnthropicAI\"\n  },\n  \"max_cost_usd\": \"0.02\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.agentrouter.to/v1/invoke', [
  'body' => '{
  "tool_id": "anyapi.twitter.search",
  "pricing_version": "pv_anyapi.twitter.search_2026-11-06_1",
  "input": {
    "limit": 10,
    "query": "from:AnthropicAI"
  },
  "max_cost_usd": "0.02"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Runs_invoke_example
using RestSharp;

var client = new RestClient("https://api.agentrouter.to/v1/invoke");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"tool_id\": \"anyapi.twitter.search\",\n  \"pricing_version\": \"pv_anyapi.twitter.search_2026-11-06_1\",\n  \"input\": {\n    \"limit\": 10,\n    \"query\": \"from:AnthropicAI\"\n  },\n  \"max_cost_usd\": \"0.02\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Runs_invoke_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "tool_id": "anyapi.twitter.search",
  "pricing_version": "pv_anyapi.twitter.search_2026-11-06_1",
  "input": [
    "limit": 10,
    "query": "from:AnthropicAI"
  ],
  "max_cost_usd": "0.02"
] as [String : Any]

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

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

### Runs_invoke_example

**Request**

```json
{
  "tool_id": "anyapi.twitter.search",
  "pricing_version": "pv_anyapi.twitter.search_2026-11-06_1",
  "input": {
    "limit": 10,
    "query": "from:AnthropicAI"
  },
  "max_cost_usd": "0.02"
}
```

**Response**

```json
{
  "object": null,
  "run_id": "string",
  "status": "READY",
  "tool_id": "string",
  "tool_version": "string",
  "provider": "string",
  "input": null,
  "session_id": "string",
  "caller": {
    "type": "api_key",
    "name": "string"
  },
  "channel": "http",
  "created_at": "string",
  "started_at": "string",
  "completed_at": "string",
  "latency_ms": 1,
  "replayed": true,
  "stoppable": true,
  "provider_response": {
    "http_status": 1,
    "outcome": "success",
    "status": "string",
    "request_id": "string",
    "task_id": "string"
  },
  "error": {
    "code": "string",
    "message": "string",
    "origin": "provider",
    "retryable": true,
    "details": {
      "body": "string",
      "truncated": true
    }
  },
  "billing": {
    "status": "none",
    "reason": "charged",
    "currency": null,
    "pricing_version": "string",
    "price_multiplier": "string",
    "promotion_id": "string",
    "max_cost_usd": "0.0035",
    "reserved_usd": "0.0035",
    "base_charge_usd": "string",
    "customer_charge_usd": "0.0035",
    "customer_refund_usd": "0.0035",
    "net_charge_usd": "0.0035",
    "charge_is_new": true,
    "usage": {
      "unit": "string",
      "quantity": "string",
      "status": "known"
    }
  },
  "result": {
    "available": true,
    "expired": true,
    "bytes": 1,
    "expires_at": "string",
    "url": "string",
    "inline": true
  },
  "next_cursor": "string",
  "hints": [
    {
      "code": "string",
      "message": "string",
      "params": {}
    }
  ],
  "output": null
}
```

**SDK Code**

```python Runs_invoke_example
import requests

url = "https://api.agentrouter.to/v1/invoke"

payload = {
    "tool_id": "anyapi.twitter.search",
    "pricing_version": "pv_anyapi.twitter.search_2026-11-06_1",
    "input": {
        "limit": 10,
        "query": "from:AnthropicAI"
    },
    "max_cost_usd": "0.02"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Runs_invoke_example
const url = 'https://api.agentrouter.to/v1/invoke';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"tool_id":"anyapi.twitter.search","pricing_version":"pv_anyapi.twitter.search_2026-11-06_1","input":{"limit":10,"query":"from:AnthropicAI"},"max_cost_usd":"0.02"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Runs_invoke_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.agentrouter.to/v1/invoke"

	payload := strings.NewReader("{\n  \"tool_id\": \"anyapi.twitter.search\",\n  \"pricing_version\": \"pv_anyapi.twitter.search_2026-11-06_1\",\n  \"input\": {\n    \"limit\": 10,\n    \"query\": \"from:AnthropicAI\"\n  },\n  \"max_cost_usd\": \"0.02\"\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 Runs_invoke_example
require 'uri'
require 'net/http'

url = URI("https://api.agentrouter.to/v1/invoke")

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  \"tool_id\": \"anyapi.twitter.search\",\n  \"pricing_version\": \"pv_anyapi.twitter.search_2026-11-06_1\",\n  \"input\": {\n    \"limit\": 10,\n    \"query\": \"from:AnthropicAI\"\n  },\n  \"max_cost_usd\": \"0.02\"\n}"

response = http.request(request)
puts response.read_body
```

```java Runs_invoke_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.agentrouter.to/v1/invoke")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"tool_id\": \"anyapi.twitter.search\",\n  \"pricing_version\": \"pv_anyapi.twitter.search_2026-11-06_1\",\n  \"input\": {\n    \"limit\": 10,\n    \"query\": \"from:AnthropicAI\"\n  },\n  \"max_cost_usd\": \"0.02\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.agentrouter.to/v1/invoke', [
  'body' => '{
  "tool_id": "anyapi.twitter.search",
  "pricing_version": "pv_anyapi.twitter.search_2026-11-06_1",
  "input": {
    "limit": 10,
    "query": "from:AnthropicAI"
  },
  "max_cost_usd": "0.02"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Runs_invoke_example
using RestSharp;

var client = new RestClient("https://api.agentrouter.to/v1/invoke");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"tool_id\": \"anyapi.twitter.search\",\n  \"pricing_version\": \"pv_anyapi.twitter.search_2026-11-06_1\",\n  \"input\": {\n    \"limit\": 10,\n    \"query\": \"from:AnthropicAI\"\n  },\n  \"max_cost_usd\": \"0.02\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Runs_invoke_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "tool_id": "anyapi.twitter.search",
  "pricing_version": "pv_anyapi.twitter.search_2026-11-06_1",
  "input": [
    "limit": 10,
    "query": "from:AnthropicAI"
  ],
  "max_cost_usd": "0.02"
] as [String : Any]

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

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