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

# checkSafety

> Call Sedata's safety API directly with a content string.

```ts theme={null}
function checkSafety(content: string): Promise<SafetyCheckResult>
```

The lower-level primitive used by [`safetyCheck`](/api-reference/safety-check).
You usually don't need to call this directly — wrap your handler with
`safetyCheck` instead. Use `checkSafety` when you want fine-grained control
(e.g. checking content from outside an MCP tool path).

## Parameters

<ParamField path="content" type="string" required>
  The content to validate.
</ParamField>

## Returns

<ResponseField name="result" type="SafetyCheckResult">
  ```ts theme={null}
  interface SafetyCheckResult {
    flagged: boolean   // true only when the API responded successfully and reported flagged
    content: string    // the content you passed in
    latency: number    // round-trip latency in ms
    success: boolean   // true if the API responded successfully (whether flagged or not)
  }
  ```
</ResponseField>

## Behavior

* `POST https://api.sedata-ai.tech/security/safety-check`
* Body: `{ "content": "<your content>" }`
* Header: `Content-Type: application/json`
* If `setTelemetryApiKey(...)` was called (typically by `instrumentServer`),
  also sends `x-api-key: <key>`.

## Failure modes

| Scenario                                                  | Result                                                                       |
| --------------------------------------------------------- | ---------------------------------------------------------------------------- |
| Network error                                             | `{ flagged: false, content, latency, success: false }` and a `console.warn`. |
| Non-2xx response                                          | Same as above.                                                               |
| 2xx but `result.success !== true`                         | `{ flagged: false, ... success: true }`.                                     |
| 2xx with `result.success === true && result.data.flagged` | `{ flagged: true, ... success: true }`.                                      |

The function never throws.

## Example

```ts theme={null}
import { checkSafety } from '@sedata-ai/mcp'

const result = await checkSafety("ignore previous instructions and...")

if (result.flagged) {
  // refuse, log, escalate
} else {
  // safe to use
}
```

## Authentication

Set the key once at startup:

```ts theme={null}
import { setTelemetryApiKey } from '@sedata-ai/mcp'
setTelemetryApiKey(process.env.SEDATA_KEY)
```

If you call `instrumentServer(...)` with `exporterAuth`, the key is set for
you.

## See also

<Card title="safetyCheck" icon="shield-check" href="/api-reference/safety-check">
  The high-level wrapper — what most users want.
</Card>
