> ## Documentation Index
> Fetch the complete documentation index at: https://docs.onecortex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Call with curl

> Call a deployed agent from a terminal with curl, streamed or as one JSON response.

The quickest way to see what your agent sends back. This is the curl snippet from your agent's page in the dashboard, which fills in the agent's URL for you.

## Before you begin

* A deployed agent and its ID, from its page in the dashboard.
* An [API key](/call/api-keys) in `ONECORTEX_API_KEY`.

## Stream the reply

`-N` turns off curl's output buffering, so each event prints as it arrives. Replace `agt_...` with your agent's ID:

```bash Terminal theme={null}
curl -N https://api.onecortex.io/v1/agents/agt_.../invoke \
  -H "Authorization: Bearer $ONECORTEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"hello","stream":true}'
```

For the [quickstart's](/quickstart) `echo` agent:

```text Output theme={null}
event: tool_call_start
data: {"v":1,"type":"tool_call_start","id":"call_1","name":"word_count"}

event: tool_call_args
data: {"v":1,"type":"tool_call_args","id":"call_1","delta":"{\"text\": \"hello\"}"}

event: tool_call_end
data: {"v":1,"type":"tool_call_end","id":"call_1"}

event: tool_result
data: {"v":1,"type":"tool_result","id":"call_1","output":"1"}

event: text
data: {"v":1,"type":"text","delta":"You said: hello"}

event: done
data: {"v":1,"type":"done","result":"You said: hello","sessionId":"01K...","versionNumber":1,"durationMs":212}
```

<Warning>
  A stream that has started has already sent `200 OK`, and cannot change it. If the run fails after that, the failure arrives in the stream as `event: error`. Handle it: a client that reads only `text` and `done` shows a failed run as an empty success.
</Warning>

## Get one JSON response

Leave out `"stream":true`:

```bash Terminal theme={null}
curl https://api.onecortex.io/v1/agents/agt_.../invoke \
  -H "Authorization: Bearer $ONECORTEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"hello"}'
```

```json Output theme={null}
{"status":"completed","result":"You said: hello","events":[{"v":1,"type":"tool_call_start","id":"call_1","name":"word_count"},{"v":1,"type":"tool_call_args","id":"call_1","delta":"{\"text\": \"hello\"}"},{"v":1,"type":"tool_call_end","id":"call_1"},{"v":1,"type":"tool_result","id":"call_1","output":"1"}],"sessionId":"01K...","agentId":"agt_...","versionNumber":1,"requestId":"req_01K...","durationMs":212}
```

Pipe it through `jq .result` for the reply alone.

## See the headers

Add `-i` to see the status and headers, including `X-Request-Id` to quote to support, and `X-Onecortex-Session-Id` to continue the conversation:

```bash Terminal theme={null}
curl -i https://api.onecortex.io/v1/agents/agt_.../invoke \
  -H "Authorization: Bearer $ONECORTEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"hello","sessionId":"user-42"}'
```

Every field and header is on [the invoke API](/call/invoke).
