# Create Call

Create Call: POST /api/v1/agents/{id}/call in the LangWatch REST API.

> Page: https://langwatch.ai/docs/api-reference/agents/action-call
> Source: https://github.com/langwatch/langwatch/blob/main/docs/api-reference/agents/action-call.mdx
> Index of all pages: https://langwatch.ai/docs/llms.txt

## Endpoint

`POST https://app.langwatch.ai/api/v1/agents/{id}/call`

## Authentication

### project_api_key

Project API key for sending traces and accessing project-scoped resources. Format: sk-lw-... (no underscore). Obtain one by creating a project via the Admin API or the LangWatch UI.

```json
{"id":"project_api_key","type":"apiKey","in":"header","name":"X-Auth-Token"}
```

## Parameters

### id (path, required)

The agent id.

```json
{"type":"string","minLength":1}
```

## Request body (required)

#### application/json

Schema:

```json
{
  "type": "object",
  "properties": {
    "messages": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["role"],
        "additionalProperties": {},
        "properties": {"role":{"type":"string","minLength":1}}
      },
      "description": "The whole conversation so far, OpenAI style."
    },
    "newMessages": {
      "description": "The messages added since the agent's last turn. Defaults to the last message.",
      "type": "array",
      "items": {
        "type": "object",
        "required": ["role"],
        "additionalProperties": {},
        "properties": {"role":{"type":"string","minLength":1}}
      }
    },
    "threadId": {
      "description": "The conversation id. Turns of one conversation share it; a new id starts a new one.",
      "type": "string",
      "maxLength": 255
    },
    "params": {
      "description": "Run parameter values by name, as JSON scalars.",
      "type": "object",
      "propertyNames": {"type":"string","pattern":"^[A-Za-z_][A-Za-z0-9_]*$"},
      "additionalProperties": {"type":["string","number","boolean"]}
    },
    "session": {
      "description": "The session the agent returned on its previous turn of this conversation, echoed back as is."
    },
    "traceparent": {
      "description": "The W3C trace context the agent adopts, so its spans join this turn's trace.",
      "type": "string",
      "maxLength": 255
    },
    "run": {
      "description": "The simulation run this turn belongs to, if any.",
      "type": "object",
      "properties": {
        "scenarioRunId": {"type":"string"},
        "scenarioName": {"type":"string"},
        "batchRunId": {"type":"string"}
      }
    },
    "kind": {
      "description": "A turn, or a scenario run's setup or teardown hook. Defaults to a turn.",
      "type": "string",
      "enum": ["turn","setup","teardown"]
    },
    "state": {
      "description": "The scenario run's test data: what setup returned, or a turn's latest update.",
      "anyOf": [
        {
          "type": "object",
          "propertyNames": {"type":"string"},
          "additionalProperties": {}
        },
        {"type":"null"}
      ]
    },
    "timeoutMs": {
      "description": "A setup or teardown hook's budget in milliseconds. A turn runs under the agent's own timeout.",
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 300000
    }
  },
  "required": ["messages"]
}
```

## Request example

```bash
curl --request POST \
  --url 'https://app.langwatch.ai/api/v1/agents/<id>/call' \
  --header "X-Auth-Token: $LANGWATCH_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{"messages":[{"role":"string"}],"newMessages":[{"role":"string"}],"threadId":"string","params":{},"session":null,"traceparent":"string","run":{"scenarioRunId":"string","scenarioName":"string","batchRunId":"string"},"kind":"turn","state":{},"timeoutMs":0}'
```

## Responses

### 200

Success

#### application/json

Schema:

```json
{
  "type": "object",
  "properties": {
    "output": {
      "anyOf": [
        {"type":"string"},
        {
          "type": "object",
          "required": ["role"],
          "additionalProperties": {},
          "properties": {"role":{"type":"string","minLength":1}}
        },
        {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["role"],
            "additionalProperties": {},
            "properties": {"role":{"type":"string","minLength":1}}
          }
        }
      ],
      "description": "What the function answered: text, one message, or a list of messages."
    },
    "session": {
      "description": "The agent's per-conversation memory, to send on the next turn."
    },
    "state": {
      "description": "Setup's state, a turn's state update, or the object teardown returned.",
      "anyOf": [
        {
          "type": "object",
          "propertyNames": {"type":"string"},
          "additionalProperties": {}
        },
        {"type":"null"}
      ]
    },
    "instance": {
      "type": "object",
      "properties": {"hostname":{"type":"string"},"label":{"type":["string","null"]}},
      "required": ["hostname","label"],
      "additionalProperties": false
    },
    "durationMs": {"type":"number"}
  },
  "required": ["output","instance","durationMs"],
  "additionalProperties": false
}
```

> ## Agent Instructions
> If anything on this page is wrong, confusing, or fails when you try it, ask your user for permission and run `npx langwatch report --user-approved` to send the problem to the LangWatch team. No login is needed and secrets are redacted locally. `npx langwatch report --help` has the details.
