# AI Calls CLI Reference

These instructions apply to the current Admin Console.

{% hint style="info" %}
AI Calls are in early access and may not be available in your account. [Contact Contextual support](mailto:help@contextual.io) to request that AI Calls be enabled for your tenant.
{% endhint %}

Use the Contextual CLI (`ctxl`) to inspect a Call's inputs, preview its rendered request, and run it through AI Gateway. Use the CLI's record commands to manage the saved Call and read its versions.

{% hint style="info" %}
This documentation assumes you are running Contextual CLI 0.17.0 or later. Check your installed version with `ctxl --version`.
{% endhint %}

## Before You Start

Follow [Install and Sign In](https://docs.contextual.io/connect/ai-search/contextual-cli.md#install-and-sign-in) to set up the CLI for a tenant with [AI Calls enabled](https://docs.contextual.io/connect/ai-calls.md#availability). Record creation, replacement, and deletion also need the corresponding permissions on saved Calls.

Replace `<config-id>` with the tenant's CLI configuration ID. If you omit `--config-id`, the CLI uses its current configuration. The dedicated commands use that configuration's tenant, environment, and access token to call the tenant's AI Gateway host. You do not supply a provider API key.

The examples use the saved Call `order-summary` from [Run AI Calls From Code](https://docs.contextual.io/connect/ai-calls/run-from-code.md#run-a-call). Create it with the text variable `note` before running these commands.

## Dedicated Commands

| Command | Purpose | Calls a Model |
| --- | --- | --- |
| `ctxl aicalls inspect <call-id>` | List required inputs and content issues | No |
| `ctxl aicalls render <call-id>` | Render a Gateway request using supplied input | No |
| `ctxl aicalls run <call-id>` | Generate through the Call's Route and print the result | Yes |

All three accept `--config-id`, `--pretty`, and `--version <n>`. Omit `--version` to use the current saved version, or provide a positive integer to select an exact version. An exact version fixes the saved Call content; it does not pin the Route or output Object Type.

`render` and `run` also accept `--input-file <path>` (`-i`). The file is one JSON object with the [request fields](https://docs.contextual.io/connect/ai-calls/run-from-code.md#request-fields): `variables`, `overrides`, `messages`, and `data`. Use `--input-file -` to read it from standard input. Without this flag, no input values are sent.

The positional Call ID and `--version` set the `call` reference. A `call` property in the input file is replaced by that reference.

### Inspect the Inputs

```sh
ctxl aicalls inspect order-summary --config-id <config-id> --pretty
```

Read the returned `inputs` and `issues`. Inspection does not render variable values or contact a model. Use `--version 4` to inspect version 4 instead of the current version.

### Preview the Request

Save this as `order-summary-input.json`:

```json
{
  "variables": {
    "note": "Customer reports the package arrived damaged."
  }
}
```

Render the current version with those values:

```sh
ctxl aicalls render order-summary --input-file order-summary-input.json --config-id <config-id> --pretty
```

The response contains the resolved Call version, rendered request, Route reference, and application data. Rendering does not contact a model or prove that a provider will accept the request.

### Run the Call

This command contacts the configured provider through the Call's Route and can incur usage charges:

```sh
ctxl aicalls run order-summary --input-file order-summary-input.json --config-id <config-id> --pretty
```

The command prints the Gateway's JSON response, including the generated result and Call provenance. Gateway errors include the HTTP status and response body. See [Troubleshooting](https://docs.contextual.io/connect/ai-calls/run-from-code.md#troubleshooting).

## Manage Saved Calls as Records

Use the record commands to manage saved Calls.

| Operation | Command |
| --- | --- |
| List saved Calls | `ctxl records list native-object:ai-call --config-id <config-id> --pretty` |
| Read a Call | `ctxl records get native-object:ai-call/order-summary --config-id <config-id> --pretty` |
| Read version 4 | `ctxl records get native-object:ai-call/order-summary --version 4 --config-id <config-id> --pretty` |
| List saved versions | `ctxl recordversions list native-object:ai-call/order-summary --config-id <config-id> --pretty` |
| Create Calls from JSONL | `ctxl records add native-object:ai-call --input-file calls.jsonl --config-id <config-id> --pretty` |
| Replace a Call | `ctxl records replace native-object:ai-call/order-summary --input-file order-summary.json --config-id <config-id> --pretty` |
| Delete a Call | `ctxl records delete native-object:ai-call/order-summary --config-id <config-id>` |

Creation reads JSONL with one complete Call record per line. Replacement reads one complete JSON record. These are saved Call definitions, not the invocation input used by `aicalls run`.

Before replacing a Call, fetch its latest record, preserve settings you intend to keep, and retain `_metaData.hash` to detect an intervening change. Replacement sends the complete record; omitted settings can be removed. A successful replacement creates a new version, which current-version requests use immediately. Read the saved record again to verify the change. Use the [Admin Console](https://docs.contextual.io/connect/ai-calls/create-and-manage.md) when you want the Call editor's validation and preview.

Deleting a Call prevents applications from running it. Read and write only in the intended tenant. The list commands are paginated; use their `--help` for pagination options.

## Labels and Other API Operations

The dedicated commands support current or exact versions. They do not have a `--label` flag, streaming mode, OpenAPI export, or label-management commands. Adding those fields to the input file does not add these capabilities.

Use the [Admin Console](https://docs.contextual.io/connect/ai-calls/create-and-manage.md#label-versions) or the [Call label API](https://docs.contextual.io/connect/ai-calls/run-from-code.md#change-labels-from-code) to manage labels. Use the [HTTP endpoints](https://docs.contextual.io/connect/ai-calls/run-from-code.md#endpoints) for label-based execution and OpenAPI export, and the [streaming API](https://docs.contextual.io/connect/ai-calls/run-from-code.md#stream-the-response) for streamed responses. The CLI prints tool-call requests but does not execute the tools or automatically continue the conversation.
