# Assess an event (/docs/api-reference/risk/create-risk-assessment)

Assesses a sign-up, login or other event in the API key's environment and returns a decision (`allow`, `review` or `block`) with a score and the reasons behind it. coss.com combines email and IP signals with what it has seen in this environment (velocity, accounts sharing a mailbox, identifiers you reported) and your allow and block lists. Signals that are unavailable at the moment are skipped and listed in `degraded`. Call it from your server, never from the browser, and treat errors as `allow` (fail open) so an outage never locks your users out. `review` decisions also fire a `risk.assessment.review` webhook. Live assessments are billed (`risk.assessments`; plans include some every month) unless they end in `block`. Past Free's allowance, on a billing hold or over a budget, they are free and made without velocity, memory or content (`usage_limit` in `degraded`); they never fail over billing. Sandbox (`coss_test_…`) keys accept documented test addresses (`192.0.2.x`, `@disposable.test`, `@undeliverable.test`).

`POST https://api.coss.com/v1/risk/assessments`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Headers

- `Idempotency-Key` (string, 1-256 characters): Makes retries safe: a repeated request with the same key and body returns the original assessment instead of assessing (and counting) the event again, for 24 hours. 1-256 characters.

## Request body

- `event` ("signup" | "login" | "message" | "checkout" | "custom", required): What is being assessed. `custom` events are named by `event_name`; velocity is counted per event.
- `event_name` (string): Required for `custom` events (e.g. `invite_sent`), not allowed otherwise.
- `user` (object)
  - `id` (string, 1-256 characters): Your id for the user, when it exists (logins always; sign-ups once the account is created).
  - `email` (string, 1-320 characters): The email address the user gave. Checked as given, even if invalid.
- `ip` (string, ip): The client's IP address (not your server's or proxy's).
- `user_agent` (string, at most 1024 characters): The client's user agent.
- `captcha` (object)
  - `token` (string, required, 1-4096 characters): The token your captcha widget (Turnstile or hCaptcha, set in the environment's risk settings) gave the browser. Verified once: don't reuse it.
- `checkout` (object): Only with `checkout` events: what is being paid for, and with which card.
  - `amount` (integer, required, 0-1000000000000): The amount in the currency's minor unit (cents for USD: 1999 is $19.99).
  - `currency` (string, required): ISO 4217, upper-case (`USD`).
  - `card` (object): What your payment processor tells you about the card.
    - `fingerprint` (string, 1-256 characters): Your payment processor's fingerprint of the card number (Stripe: `card.fingerprint`). Counted and remembered as a keyed hash only; never send the card number.
    - `country` (string): Where the card was issued.
    - `funding` ("credit" | "debit" | "prepaid" | "unknown")
  - `billing_country` (string): ISO 3166-1 alpha-2, upper-case (`GB`).
  - `shipping_country` (string): ISO 3166-1 alpha-2, upper-case (`GB`).
- `device` (object): The browser the event came from: recognizes it across accounts (`duplicate.device`, device velocity, fraud memory) and spots automation.
  - `token` (string, required, 1-4096 characters): What `collectDevice()` from `coss/device` returned in the user's browser, passed through your server.
- `content` (object): Content to classify with the event. Its scores go in `signals.content` and rules can test them; `content.*` reasons fire only at thresholds you set.
  - `text` (string, required, 1-50000 characters): Text the user wrote (a profile bio, a message, a listing). Classified by an AI model with zero data retention and never stored: only its scores are.

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.risk.assess({
  event: "signup",
  user: {
    email: "ada@gmail.con",
  },
  ip: "203.0.113.7",
  user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15",
}, {
  idempotencyKey: "welcome-user-123",
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/risk/assessments" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Idempotency-Key: welcome-user-123" \
  -H "Content-Type: application/json" \
  -d '{
  "event": "signup",
  "user": {
    "email": "ada@gmail.con"
  },
  "ip": "203.0.113.7",
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15"
}'
```

Python:

```python
from coss import Coss
from coss.risk import CreateRiskAssessmentRequestUser

client = Coss()  # api_key= or COSS_API_KEY

client.risk.assess(
    idempotency_key="welcome-user-123",
    event="signup",
    user=CreateRiskAssessmentRequestUser(
        email="ada@gmail.con",
    ),
    ip="203.0.113.7",
    user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15",
)
```

Go:

```go
import (
	"context"

	coss "github.com/cosscom/coss-go"
	cossclient "github.com/cosscom/coss-go/client"
)

client := cossclient.NewClient() // option.WithAPIKey(…) or COSS_API_KEY

request := &coss.CreateRiskAssessmentRequest{
    IdempotencyKey: coss.String(
        "welcome-user-123",
    ),
    Event: coss.RiskEventSignup,
    User: &coss.CreateRiskAssessmentRequestUser{
        Email: coss.String(
            "ada@gmail.con",
        ),
    },
    IP: coss.String(
        "203.0.113.7",
    ),
    UserAgent: coss.String(
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15",
    ),
}
client.Risk.Assess(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

client = Coss::Client.new # api_key: or COSS_API_KEY

client.risk.assess(
  idempotency_key: "welcome-user-123",
  event: "signup",
  user: {
    email: "ada@gmail.con"
  },
  ip: "203.0.113.7",
  user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15"
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Risk\Requests\CreateRiskAssessmentRequest;
use Coss\Risk\Types\CreateRiskAssessmentRequestUser;
use Coss\Types\RiskEvent;

$client = new Coss(); // apiKey: or COSS_API_KEY

$client->risk->assess(
    new CreateRiskAssessmentRequest([
        'idempotencyKey' => 'welcome-user-123',
        'event' => RiskEvent::Signup->value,
        'user' => new CreateRiskAssessmentRequestUser([
            'email' => 'ada@gmail.con',
        ]),
        'ip' => '203.0.113.7',
        'userAgent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15',
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.risk.requests.CreateRiskAssessmentRequest;
import com.coss.resources.risk.types.CreateRiskAssessmentRequestUser;
import com.coss.types.RiskEvent;

Coss client = Coss.builder().build(); // .apiKey(…) or COSS_API_KEY

client.risk().assess(
    CreateRiskAssessmentRequest
        .builder()
        .event(RiskEvent.SIGNUP)
        .idempotencyKey("welcome-user-123")
        .user(
            CreateRiskAssessmentRequestUser
                .builder()
                .email("ada@gmail.con")
                .build()
        )
        .ip("203.0.113.7")
        .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15")
        .build()
);
```

.NET:

```csharp
using Coss;

var client = new CossClient(); // apiKey: or COSS_API_KEY

await client.Risk.AssessAsync(
    new CreateRiskAssessmentRequest
    {
        IdempotencyKey = "welcome-user-123",
        Event = RiskEvent.Signup,
        User = new CreateRiskAssessmentRequestUser { Email = "ada@gmail.con" },
        Ip = "203.0.113.7",
        UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15",
    }
);
```

## Response 201

The assessment. A replay returns the original assessment.

- `object` ("risk_assessment", required)
- `id` (string, required)
- `event` ("signup" | "login" | "message" | "checkout" | "custom", required): What is being assessed. `custom` events are named by `event_name`; velocity is counted per event.
- `event_name` (string | null, required): Your name for a `custom` event. `null`: none.
- `decision` ("allow" | "review" | "block", required): `allow`: go ahead. `review`: suspicious; let it through with limits, or hold it for a person. `block`: refuse it.
- `score` (number, required, 0-1): 0-1: how risky the signals are together. Lists can decide regardless of the score.
- `reasons` (object[], required): Why, most significant first.
  - `code` (string, required, one of "email.invalid", "email.disposable", "email.undeliverable", "email.role_account", "email.typo", "email.domain_new", "ip.tor", "ip.vpn_network", "ip.hosting_provider", "ip.vpn", "ip.proxy", "ip.relay", "ip.private", "velocity.signups_per_ip_1h", "velocity.signups_per_ip_24h", "velocity.signups_per_subnet_1h", "velocity.signups_per_email_domain_1h", "velocity.signups_per_mailbox_24h", "velocity.signups_per_device_24h", "velocity.checkouts_per_ip_1h", "velocity.checkouts_per_user_1h", "velocity.checkouts_per_card_24h", "velocity.logins_per_ip_1h", "velocity.logins_per_user_1h", "velocity.events_per_ip_1h", "velocity.events_per_user_1h", "duplicate.canonical_mailbox", "duplicate.device", "history.fraud_mailbox", "history.fraud_user", "history.fraud_ip", "history.fraud_subnet", "history.fraud_card", "history.fraud_device", "checkout.card_country_mismatch", "checkout.billing_country_mismatch", "checkout.prepaid_card", "device.automation", "device.invalid", "login.new_country", "login.new_network", "captcha.failed", "captcha.missing", "content.spam", "content.phishing", "content.malware", "content.fraud", "rule.matched", "list.blocked", "list.allowed"): The reason's code, listed under Risk's reasons in the docs.
  - `message` (string, required): What it means, in words. May change.
  - `value` (number): The count behind a `velocity.*` reason, or the score behind a `content.*` one.
  - `threshold` (number): What a `velocity.*` or `content.*` reason fires at.
  - `window` ("1h" | "24h"): `velocity.*`: the window it's counted over.
  - `suggestion` (string): `email.typo`: the likely domain.
  - `provider` (string): `ip.hosting_provider`, `ip.vpn_network`: the network's operator; `ip.vpn`: the VPN service.
  - `previous_user` (string | null): `duplicate.canonical_mailbox`, `duplicate.device`: your id of the user who has the mailbox or device, if known.
  - `previous_assessment` (string): `duplicate.canonical_mailbox`, `duplicate.device`: the assessment that first saw the mailbox or device.
  - `entry` (string): `list.*`: the matching list entry.
  - `rule` (string): `rule.matched`: the rule's id.
  - `name` (string): `rule.matched`: the rule's name.
  - `type` ("email" | "domain" | "ip" | "asn" | "country" | "user"): `list.*`: what matched.
- `signals` (object, required): What the assessment saw, by group. A group is `null` when it had nothing to go on.
  - `email` (object | null, required): What the address says. `null`: no email was given.
    - `domain` (string | null, required): `null` once the address is removed (90 days after the assessment).
    - `valid` (boolean, required): Whether it's syntactically valid.
    - `disposable` (boolean, required): Whether its domain is a known burner service.
    - `deliverability` ("deliverable" | "undeliverable" | "unknown", required): From DNS (MX, A, AAAA). `unknown` when the lookup failed or timed out.
    - `role_account` (boolean, required): Whether it's a role mailbox, like `info@`.
    - `free_provider` (boolean, required): Whether its domain is a free mailbox provider.
    - `suggestion` (string | null, required): `email.typo`: the likely intended domain. `null` otherwise.
    - `domain_age_days` (integer | null, required): Days since the domain was registered (RDAP); `null` when unknown or not looked up (free providers, disposable domains).
  - `ip` (object | null, required): What the IP address says. `null`: none was given.
    - `version` (4 | 6, required): IPv4 or IPv6.
    - `private` (boolean, required): Whether it's a private or reserved address.
    - `tor` (boolean, required): Whether it's a Tor exit.
    - `hosting` (boolean, required): Whether it's in a cloud, hosting or VPN network.
    - `hosting_provider` (string | null, required): That network's operator. `null` when it isn't one.
    - `hosting_kind` ("cloud" | "hosting" | "vpn" | null, required): `cloud`, `hosting` or `vpn`. `null` when it isn't one.
    - `asn` (integer | null, required): The network's autonomous system number. `null` when unknown.
    - `as_name` (string | null, required): The network's name. `null` when unknown.
    - `country` (string | null, required): ISO 3166-1 alpha-2.
    - `privacy` (object | null, required): From coss.com's IP privacy data provider (VPNs, proxies, relays). `null` when it isn't available or was not asked (private addresses).
      - `vpn` (boolean, required): Whether it's a VPN exit.
      - `proxy` (boolean, required): Whether it's a proxy.
      - `relay` (boolean, required): Whether it's a privacy relay.
      - `service` (string | null, required): The VPN or proxy service.
  - `velocity` (map of integer | null, required): `null` when velocity was unavailable (see `degraded`).
  - `captcha` (object | null, required): How the captcha went. `null`: no captcha applied.
    - `provided` (boolean, required): Whether the request carried a token.
    - `passed` (boolean | null, required): `null` when it couldn't be checked (no captcha configured, or the provider was unreachable).
  - `login` (object | null, required): Whether a login is new for this user. `null`: not a login of a user with history.
    - `new_country` (boolean, required): Whether this user never logged in from this country in this environment.
    - `new_network` (boolean, required): Whether this user never logged in from this network (ASN) in this environment.
  - `content` (object | null, required): `null` when no content was given or it couldn't be classified.
    - `spam` (number, required, 0-1): The model's probability (0-1) that it's spam.
    - `phishing` (number, required, 0-1): The model's probability (0-1) that it's phishing.
    - `malware` (number, required, 0-1): The model's probability (0-1) that it's malware.
    - `fraud` (number, required, 0-1): The model's probability (0-1) that it's fraud.
  - `checkout` (object | null, required): What you sent in `checkout`. `null`: not given.
    - `amount` (integer, required): The amount you sent, in the currency's smallest unit.
    - `currency` (string, required): The currency you sent.
    - `card_country` (string | null, required): The card's country. `null` when not given.
    - `card_funding` ("credit" | "debit" | "prepaid" | "unknown" | null, required): The card's funding type. `null` when not given.
    - `billing_country` (string | null, required): The billing country. `null` when not given.
    - `shipping_country` (string | null, required): The shipping country. `null` when not given.
  - `device` (object | null, required): What the device token said. `null`: none was given.
    - `valid` (boolean, required): `false`: the token was malformed or too old.
    - `automation` (boolean, required): WebDriver control or a headless browser.
    - `timezone` (string | null, required): IANA time zone (`Europe/London`).
    - `language` (string | null, required): The browser's first language.
    - `platform` (string | null, required): The browser's reported platform. `null` when it reported none.
    - `screen` (string | null, required): `<width>x<height>` in CSS pixels.
    - `touch` (boolean | null, required): Whether the device has a touch screen. `null` when it didn't say.
- `user` (object, required): Who it's about.
  - `id` (string | null, required): Your user id. `null`: none given.
  - `email` (string | null, required): `null` once removed (90 days after the assessment) or when none was given.
- `ip` (string | null, required): `null` once removed (90 days after).
- `degraded` (("email_dns" | "domain_age" | "ip_data" | "velocity" | "captcha" | "content" | "ip_privacy" | "usage_limit")[], required): Signal groups that were unavailable for this assessment (it was made without them). `usage_limit` means the plan's included assessments are used up, or a billing hold or budget applies: the assessment was free and made without velocity, memory of earlier events, content or address-level IP data.
- `outcome` ("legitimate" | "fraud" | "abuse" | null, required): The latest outcome you reported with feedback.
- `review_status` ("open" | "resolved" | null, required): `open` for `review` decisions until you send feedback, then `resolved`.
- `created_at` (string, required, date-time)

Example:

```json
{
  "object": "risk_assessment",
  "id": "rsk_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "event": "signup",
  "event_name": null,
  "decision": "review",
  "score": 0.62,
  "reasons": [
    {
      "code": "email.typo",
      "message": "The domain looks like a typo of gmail.com.",
      "suggestion": "gmail.com"
    },
    {
      "code": "velocity.signups_per_ip_1h",
      "message": "7 sign-ups from this IP address in the last hour.",
      "value": 7,
      "threshold": 5,
      "window": "1h"
    }
  ],
  "signals": {
    "email": {
      "domain": "gmail.con",
      "valid": true,
      "disposable": false,
      "deliverability": "deliverable",
      "role_account": false,
      "free_provider": false,
      "suggestion": "gmail.com",
      "domain_age_days": 9
    },
    "ip": {
      "version": 4,
      "private": false,
      "tor": false,
      "hosting": false,
      "hosting_provider": null,
      "hosting_kind": null,
      "asn": 64500,
      "as_name": "Example Broadband",
      "country": "GB",
      "privacy": null
    },
    "velocity": {
      "ip_1h": 7,
      "ip_24h": 9,
      "subnet_1h": 7,
      "mailbox_24h": 1
    },
    "captcha": {
      "provided": true,
      "passed": true
    },
    "login": null,
    "content": null,
    "checkout": null,
    "device": null
  },
  "user": {
    "id": null,
    "email": "ada@gmail.con"
  },
  "ip": "203.0.113.7",
  "degraded": [],
  "outcome": null,
  "review_status": "open",
  "created_at": "2026-01-15T09:30:00.000Z"
}
```

## Errors

- `400`: The body is not valid JSON (`invalid_json`) or the `Idempotency-Key` header is invalid (`invalid_idempotency_key`). Also when the `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `409`: Requests with this `Idempotency-Key` are racing for an expired key (`request_in_progress`). Retry after `Retry-After` seconds.
- `413`: The request body is larger than 5 MB (`payload_too_large`).
- `415`: The body is not sent as `application/json` (`unsupported_media_type`).
- `422`: The body failed validation (`validation_error`, see `issues`), or the `Idempotency-Key` was already used with a different body (`idempotency_key_reused`).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).