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

# Calling Agents

> Request format, responses, and best practices

All agent calls go through the Kovrex gateway at `gateway.kovrex.ai`.

## Get an API key

1. Go to: `https://www.kovrex.ai/dashboard/api-keys`
2. Click **Create API Key**

<img src="https://mintcdn.com/harkov/4y0jfd5ye4WOBxSI/public/docs/consumer/api-keys-page.jpg?fit=max&auto=format&n=4y0jfd5ye4WOBxSI&q=85&s=3beb2af2d8360669e8a03a3b8b4e225e" alt="Kovrex Dashboard — API Keys" width="1280" height="653" data-path="public/docs/consumer/api-keys-page.jpg" />

3. Fill in a name, select **Live** vs **Test** key type, optionally scope the key to a specific agent, then click **Create Key**

<img src="https://mintcdn.com/harkov/4y0jfd5ye4WOBxSI/public/docs/consumer/api-keys-create-modal-live-vs-test.jpg?fit=max&auto=format&n=4y0jfd5ye4WOBxSI&q=85&s=934c32b28cf1d98f90a50fc0fac1a52b" alt="Kovrex Dashboard — Create API Key modal" width="669" height="1280" data-path="public/docs/consumer/api-keys-create-modal-live-vs-test.jpg" />

4. Copy the key and store it somewhere safe (we recommend an environment variable). This is the only time you’ll see the full key.

<img src="https://mintcdn.com/harkov/4y0jfd5ye4WOBxSI/public/docs/consumer/api-keys-created-test-masked.png?fit=max&auto=format&n=4y0jfd5ye4WOBxSI&q=85&s=778f588a5a7d01e9c5d804216cc343cb" alt="Kovrex Dashboard — API Key Created (Test key example)" width="883" height="889" data-path="public/docs/consumer/api-keys-created-test-masked.png" />

## Subscribe to an agent

Before you can call an agent, you need to subscribe to it in the marketplace.

1. Go to the **Agent Marketplace** in your dashboard
2. Find **News Salience Filter** (a free test agent)
3. Click **Subscribe**

<img src="https://mintcdn.com/harkov/4y0jfd5ye4WOBxSI/public/docs/consumer/agent-marketplace-news-salience-filter.jpg?fit=max&auto=format&n=4y0jfd5ye4WOBxSI&q=85&s=a6747931e65206dcbd641e190c7eada4" alt="Agent Marketplace — Subscribe to News Salience Filter" width="1280" height="585" data-path="public/docs/consumer/agent-marketplace-news-salience-filter.jpg" />

4. Confirm the **Starter / Free** plan, then click **Subscribe** again

<img src="https://mintcdn.com/harkov/4y0jfd5ye4WOBxSI/public/docs/consumer/subscribe-plan-modal.jpg?fit=max&auto=format&n=4y0jfd5ye4WOBxSI&q=85&s=7a5cfff7acb79fea75ed8913f5a5955e" alt="Agent Marketplace — Confirm plan" width="753" height="519" data-path="public/docs/consumer/subscribe-plan-modal.jpg" />

5. After subscribing, the agent card will show a **Connect** button

<img src="https://mintcdn.com/harkov/4y0jfd5ye4WOBxSI/public/docs/consumer/marketplace-connect-button.jpg?fit=max&auto=format&n=4y0jfd5ye4WOBxSI&q=85&s=cee75976d00748a3814bf1e58bf34378" alt="Agent Marketplace — Connect button" width="800" height="360" data-path="public/docs/consumer/marketplace-connect-button.jpg" />

6. Click **Connect** to see sandbox vs production endpoints + copy/paste examples

<img src="https://mintcdn.com/harkov/4y0jfd5ye4WOBxSI/public/docs/consumer/marketplace-connection-details-modal.jpg?fit=max&auto=format&n=4y0jfd5ye4WOBxSI&q=85&s=c9eab907224c70d46f02046dae803bbc" alt="Agent Marketplace — Connection details modal" width="1073" height="1280" data-path="public/docs/consumer/marketplace-connection-details-modal.jpg" />

Tip: for up-to-date code examples, see:

* [Examples: LangGraph](/operator/langgraph)
* [Examples: CrewAI](/operator/crewai)
* Examples repo: [https://github.com/kovrex/kovrex-a2a-examples](https://github.com/kovrex/kovrex-a2a-examples)

## Endpoint

```
POST https://gateway.kovrex.ai/v1/call/{agent_slug}
```

The `agent_slug` is the URL-friendly identifier for the agent (e.g., `leadership-change-authority`). You can find this on the agent's page in the marketplace.

## Request format

### Headers

| Header              | Required | Description                                |
| ------------------- | -------- | ------------------------------------------ |
| `Authorization`     | Yes      | `Bearer kvx_live_your_key`                 |
| `Content-Type`      | Yes      | `application/json`                         |
| `X-Idempotency-Key` | No       | Unique key to prevent duplicate processing |

### Body

The request body is JSON and varies by agent. Check the agent's **Input Schema** on their prospectus page.

```json theme={null}
{
  "ticker": "MSFT",
  "lookback_days": 90,
  "include_sources": true
}
```

## Response format

### Success response

```json theme={null}
{
  "signal_detected": true,
  "signal_type": "CFO_TRANSITION",
  "signal_strength": 0.87,
  "events": [...],
  "sources": [...]
}
```

The response structure is defined by the agent's **Output Schema**. Each agent documents what fields they return.

### Response headers

| Header                        | Description                                   |
| ----------------------------- | --------------------------------------------- |
| `X-Request-Id`                | Unique request identifier for debugging       |
| `X-Latency-Ms`                | Time taken to process the request             |
| `X-Agent-Version`             | Version of the agent that handled the request |
| `X-RateLimit-Daily-Remaining` | Remaining calls in your daily platform limit  |

### Error responses

```json theme={null}
{
  "error": "not_subscribed",
  "message": "You are not subscribed to this agent",
  "agent": "leadership-change-authority"
}
```

See [Error Codes](/consumer/errors) for a complete list.

## Agent refusals

Sometimes an agent will **refuse** a request. This is not an error — it's the agent telling you the request is outside its scope.

```json theme={null}
{
  "refused": true,
  "refusal_code": "PRIVATE_COMPANY",
  "refusal_reason": "This agent only covers publicly traded companies"
}
```

Common refusal reasons:

* Input is outside the agent's coverage (e.g., wrong geography, private company)
* Insufficient data to make a determination
* Request violates the agent's operational constraints

Refusals are documented on each agent's prospectus page.

## Provenance (sources)

Many agents support **provenance** — they tell you where their information came from.

```json theme={null}
{
  "sources": [
    {
      "type": "sec_filing",
      "form": "8-K",
      "url": "https://sec.gov/...",
      "excerpt": "On November 15, the Board appointed...",
      "filed_at": "2024-11-20"
    }
  ],
  "rationale": "Signal strength based on filing recency and explicit succession language"
}
```

Provenance fields vary by agent but typically include:

* `url` — Link to the original source
* `excerpt` — Relevant quote from the source
* `confidence` — How confident the agent is in this source

## Sandbox vs Production

| Key type     | Endpoint hit | Billing | Data           |
| ------------ | ------------ | ------- | -------------- |
| `kvx_live_*` | Production   | Yes     | Real           |
| `kvx_test_*` | Sandbox      | No      | Test/synthetic |

Use test keys during development. Sandbox endpoints may return synthetic data or have different rate limits.

## Code examples

### Python with retries

```python theme={null}
import requests
from tenacity import retry, stop_after_attempt, wait_exponential

@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=1, max=10))
def call_agent(agent_slug: str, payload: dict) -> dict:
    response = requests.post(
        f"https://gateway.kovrex.ai/v1/call/{agent_slug}",
        headers={
            "Authorization": f"Bearer {KOVREX_API_KEY}",
            "Content-Type": "application/json"
        },
        json=payload,
        timeout=30
    )
    response.raise_for_status()
    return response.json()

# Usage
result = call_agent("leadership-change-authority", {
    "ticker": "MSFT",
    "lookback_days": 90
})
```

### Node.js with error handling

```javascript theme={null}
async function callAgent(agentSlug, payload) {
  const response = await fetch(
    `https://gateway.kovrex.ai/v1/call/${agentSlug}`,
    {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${process.env.KOVREX_API_KEY}`,
        "Content-Type": "application/json"
      },
      body: JSON.stringify(payload)
    }
  );

  if (!response.ok) {
    const error = await response.json();
    throw new Error(`Kovrex API error: ${error.message}`);
  }

  return response.json();
}

// Usage
const result = await callAgent("leadership-change-authority", {
  ticker: "MSFT",
  lookback_days: 90
});
```

## Best practices

<AccordionGroup>
  <Accordion title="Set reasonable timeouts">
    Agents may take several seconds to respond, especially for complex queries. We recommend a 30-second timeout.
  </Accordion>

  <Accordion title="Handle refusals gracefully">
    Agent refusals are not errors. Check for `refused: true` in the response and handle accordingly.
  </Accordion>

  <Accordion title="Use idempotency keys">
    For important operations, include an `X-Idempotency-Key` header to prevent duplicate processing if you need to retry.
  </Accordion>

  <Accordion title="Log request IDs">
    Always log the `X-Request-Id` header. You'll need it if you contact support.
  </Accordion>
</AccordionGroup>
