# AI agent and bot detection (/score-api/endpoints/bot-detection)



{/* Written by scripts/build-use-cases.mjs from internal/usecases/catalog.json and use-cases/site.json. Change those, not this file. */}

**Tell the agents that work for your customers from the bots that attack them.** Some automated traffic is a customer's own agent placing an order. Some is a script testing stolen cards. Describe the session, and get a score for how likely it is automated abuse.

| Endpoint             | Price           | Group          |
| -------------------- | --------------- | -------------- |
| `POST /v1/score/bot` | $0.002 per call | Policy & Abuse |

## Request [#request]

Send what you know in one `context` object. `session` is required; every other field is optional. A field can hold text, JSON or CSV.

<Tabs items="[&#x22;curl&#x22;, &#x22;Python&#x22;, &#x22;TypeScript&#x22;]">
  <Tab value="curl">
    ```bash
    curl https://api.finic.ai/v1/score/bot \
      --header "Authorization: Bearer $FINIC_API_KEY" \
      --header "Content-Type: application/json" \
      --data '{
        "context": {
          "session": { "duration_seconds": 60, "checkout_attempts": 42, "distinct_cards": 42, "pointer_events": 0, "median_ms_between_actions": 140 },
          "user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/126.0.0.0 Safari/537.36",
          "ip": { "address": "192.0.2.146", "type": "datacenter", "city": "Ashburn", "region": "VA", "sessions_today": 300 },
          "account": { "signed_in": false, "checkout": "guest" },
          "device": { "webdriver": true, "plugins": 0, "screen": "800x600" }
        }
      }'
    ```
  </Tab>

  <Tab value="Python">
    ```python
    import os
    import requests

    response = requests.post(
        "https://api.finic.ai/v1/score/bot",
        headers={"Authorization": f"Bearer {os.environ['FINIC_API_KEY']}"},
        json={
            "context": {
                "session": { "duration_seconds": 60, "checkout_attempts": 42, "distinct_cards": 42, "pointer_events": 0, "median_ms_between_actions": 140 },
                "user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/126.0.0.0 Safari/537.36",
                "ip": { "address": "192.0.2.146", "type": "datacenter", "city": "Ashburn", "region": "VA", "sessions_today": 300 },
                "account": { "signed_in": False, "checkout": "guest" },
                "device": { "webdriver": True, "plugins": 0, "screen": "800x600" }
            }
        },
        timeout=30,
    )
    response.raise_for_status()
    print(response.json()["score"])
    ```
  </Tab>

  <Tab value="TypeScript">
    ```ts
    const response = await fetch("https://api.finic.ai/v1/score/bot", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.FINIC_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        context: {
          "session": { "duration_seconds": 60, "checkout_attempts": 42, "distinct_cards": 42, "pointer_events": 0, "median_ms_between_actions": 140 },
          "user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/126.0.0.0 Safari/537.36",
          "ip": { "address": "192.0.2.146", "type": "datacenter", "city": "Ashburn", "region": "VA", "sessions_today": 300 },
          "account": { "signed_in": false, "checkout": "guest" },
          "device": { "webdriver": true, "plugins": 0, "screen": "800x600" }
        },
      }),
    });
    const { score, questions } = await response.json();
    ```
  </Tab>
</Tabs>

## Fields you send [#fields-you-send]

Send the details, not only an ID: an account ID tells the score nothing, but the account's age, profile and history do. Fields that are not in this list are also read.

| Field            |          | Description                                                                                                                 |
| ---------------- | -------- | --------------------------------------------------------------------------------------------------------------------------- |
| `session`        | Required | What the session did: its events or its counts, with timings.                                                               |
| `user_agent`     | Optional | The full user agent string, with any client hints.                                                                          |
| `ip`             | Optional | The IP address with what your lookup says about it: country, city and network type. An address by itself says little.       |
| `account`        | Optional | A description of the account in use, not an account ID: its age, its history, and whether the customer has set up an agent. |
| `declared_agent` | Optional | What the client says it is, if it identifies itself as an agent, and who it says it acts for.                               |
| `device`         | Optional | A description of the device: its fingerprint traits, and the other sessions seen on it.                                     |
| `other_context`  | Optional | Any other information, structured or unstructured, that is useful for scoring.                                              |

## Response [#response]

`score` runs from 0, the lowest risk, to 1000, the highest. `questions` are the yes/no questions behind it, each with the probability that the answer is yes.

```json title="200 OK"
{
  "score": 968,
  "questions": [
    {
      "text": "Are actions arriving faster than a person could click?",
      "probability": 0.97
    },
    {
      "text": "Is one client trying many cards or accounts?",
      "probability": 0.96
    },
    {
      "text": "Does the browser report traits of an automation tool?",
      "probability": 0.94
    },
    {
      "text": "Is this an agent acting for a signed-in customer?",
      "probability": 0.04
    }
  ],
  "request_id": "req_01M4YF1068X8B4C458ENPD4JHT"
}
```

## The questions behind the score [#the-questions-behind-the-score]

1. Are actions arriving faster than a person could click?
2. Is one client trying many cards or accounts?
3. Does the browser report traits of an automation tool?
4. Is this an agent acting for a signed-in customer?

Every organization gets the same questions for this score. To use your own questions, or to calibrate a score to your own outcomes, copy it to a [custom scoring model](/score-model) in the Finic app (Starter plan and above).

## Turn the score into an action [#turn-the-score-into-an-action]

These thresholds are examples. Choose your own, and change them as you learn.

| Score       | Action  | Example                          |
| ----------- | ------- | -------------------------------- |
| Under 300   | Approve | Let the session go on.           |
| 300 to 599  | Step up | Show a challenge.                |
| 600 to 849  | Review  | Flag the session for an analyst. |
| 850 or more | Block   | End the session.                 |

## Errors [#errors]

| Status | `type`                 | When                                                                                                           |
| ------ | ---------------------- | -------------------------------------------------------------------------------------------------------------- |
| 400    | `invalid_request`      | `context` is missing, is not a JSON object, or a required field (`session`) is empty. `param` names the field. |
| 401    | `authentication_error` | The API key is missing or not valid.                                                                           |
| 402    | `insufficient_credit`  | The organization has no credit. Add credit in the Finic app.                                                   |
| 429    | `rate_limited`         | Too many requests. Retry with exponential backoff.                                                             |

See the [API reference](/reference) for every error and limit, and [Pricing](/pricing) for what a call costs.
