# OCSF / SIEM export

Send AI activity and audit events to your SIEM as OCSF 1.9.0 events, pulled with an API key or pushed to a signed webhook, and push OCSF events from other tools into LangWatch.

> Page: https://langwatch.ai/docs/ai-gateway/governance/ocsf-export
> Source: https://github.com/langwatch/langwatch/blob/main/docs/ai-gateway/governance/ocsf-export.mdx
> Index of all pages: https://langwatch.ai/docs/llms.txt

## What is exported

LangWatch exports three streams of OCSF 1.9.0 API Activity events (`class_uid` 6003, `category_uid` 6):

| Stream | Route | Contains |
|---|---|---|
| Governance events | `GET /api/governance/ocsf/events` | Traces from [ingestion sources](https://langwatch.ai/docs/ai-governance/ingestion-sources/index), events pulled from provider audit APIs, admin views of a member's or team's workspace, and OCSF events pushed in from other tools |
| Project traces | `GET /api/governance/ocsf/traces` | One event per trace in the organization's projects |
| Audit log | `GET /api/governance/ocsf/audit` | Admin and configuration actions: who did what, on which target, from which address, and whether it failed |

Every event LangWatch builds sets `metadata.version` to `1.9.0`, `metadata.uid` to a stable event id and `metadata.tenant_uid` to the organization id. An LLM call is `activity_id` 99 (Other) with `activity_name` `Invoke`, since OCSF API Activity has no invoke activity.

## AI fields

Each event carries the OCSF 1.9 AI objects when LangWatch knows their values:

| Field | Source |
|---|---|
| `ai_model.name`, `ai_model.ai_provider` | The model the call used. A `provider/model` name is split; an unknown provider is `Unknown` |
| `ai_agent.name`, `ai_agent.uid` | `gen_ai.agent.name` and `gen_ai.agent.id` on the trace |
| `message_context.prompt_tokens`, `completion_tokens`, `total_tokens` | The trace's or the provider event's token counts |
| `message_context.uid`, `metadata.correlation_uid` | The trace id |
| `unmapped.langwatch.cost_usd` | The cost in USD. Provider events priced in another currency carry `cost_amount` and `cost_currency` instead |

Prompt and response text are never exported, and neither is the raw provider payload. `unmapped.langwatch` also carries `source_type`, `source_id`, `trace_id` and `project_id` so you can pivot back to LangWatch.

## Auth

| Requirement | Value |
|---|---|
| Plan | Enterprise |
| Credential | An organization API key, sent as `Authorization: Bearer <key>` |
| Permission | `complianceExport:view` for the three export routes, `governance:manage` for the ingest route |

A key without the permission gets a 403. An organization below Enterprise gets a 402 `enterprise_plan_required`.

## Pulling events

All three routes take the same paging parameters:

| Parameter | Default | Purpose |
|---|---|---|
| `limit` | `500` | Page size, 1 to 1000 |
| `cursor` | none | The `next_cursor` of the previous page |
| `since` | none | ISO 8601 start of the first read. A cursor carries its own position |
| `until` | none | ISO 8601 end bound. The cursor does not carry it, so send it again with every page |

`/events` also takes `source_type` and `source_id`. `/traces` takes `project_id` to read one project. `/audit` returns an entry once it is ten minutes old, so an entry written late is not skipped by a cursor that already passed its time.

Every page answers `next_cursor`, which is always set, and `has_more`. Store `next_cursor` after each page. While `has_more` is true, read again at once; when it is false, wait for your next scheduled run and pass the stored cursor. A trace updated after it was exported is exported again with the same `metadata.uid`, so deduplicate on it.

```bash
curl -s "https://app.langwatch.ai/api/governance/ocsf/events?limit=500" \
  -H "Authorization: Bearer $LANGWATCH_ORG_API_KEY"
```

```json
{
  "ocsf_version": "1.9.0",
  "data": [
    {
      "class_uid": 6003,
      "class_name": "API Activity",
      "category_uid": 6,
      "activity_id": 99,
      "activity_name": "Invoke",
      "type_uid": 600399,
      "severity_id": 1,
      "time": 1763114521123,
      "status_id": 0,
      "actor": { "user": { "uid": "user_01H...", "email_addr": "jane@acme.com" } },
      "api": { "operation": "trace.recorded", "service": { "name": "LangWatch" } },
      "src_endpoint": { "name": "otel_generic" },
      "cloud": { "provider": "openai" },
      "osint": [],
      "ai_model": { "name": "gpt-5-mini", "ai_provider": "openai" },
      "ai_agent": { "name": "billing-agent" },
      "message_context": {
        "uid": "trace_01H...",
        "prompt_tokens": 120,
        "completion_tokens": 30,
        "total_tokens": 150
      },
      "metadata": {
        "version": "1.9.0",
        "uid": "trace_01H...",
        "product": { "name": "LangWatch", "vendor_name": "LangWatch" },
        "tenant_uid": "organization_01H...",
        "log_name": "governance",
        "correlation_uid": "trace_01H..."
      },
      "unmapped": {
        "langwatch": {
          "source_type": "otel_generic",
          "source_id": "src_01H...",
          "trace_id": "trace_01H...",
          "cost_usd": 0.0042
        }
      }
    }
  ],
  "next_cursor": "eyJ0IjoxNzYzMTE0NTIxMTIzLCJlIjoidHJhY2VfMDFIIn0",
  "has_more": false
}
```

## Pushing events to your SIEM

Create a [webhook endpoint](https://langwatch.ai/docs/features/webhooks) subscribed to `ocsf.event`, pointing at your SIEM's HTTP collector or a forwarder in front of it:

```bash
curl -s "https://app.langwatch.ai/api/webhooks/v1/endpoints" \
  -H "Authorization: Bearer $LANGWATCH_ORG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://siem-forwarder.acme.com/langwatch", "enabled_events": ["ocsf.event"]}'
```

LangWatch queues each governance event when it is written. Deliveries use the standard webhook envelope: a POST holds a `batch` of up to `max_batch_size` webhook events (100 by default), each with `type: "ocsf.event"` and one OCSF 1.9.0 event as its `data`:

```json
{
  "batch": [
    {
      "id": "evt_f905578f982aee17650a4616b89ad219",
      "type": "ocsf.event",
      "created": "2026-11-16T16:47:29.124Z",
      "schema_version": "1",
      "data": { "class_uid": 6003, "activity_name": "Invoke", "metadata": { "uid": "47c84f48...", "version": "1.9.0" } }
    }
  ]
}
```

Deliveries are signed with `X-LangWatch-Signature: t=<unix seconds>,v1=<hmac-sha256>`, retried with backoff, and logged per endpoint; see [verifying signatures](https://langwatch.ai/docs/features/webhooks#verifying-signatures). An event written again, for example when a trace is processed twice, keeps its idempotency key, so it is queued once per endpoint. A retry after a lost acknowledgement can deliver it again, so deduplicate on `metadata.uid`.

OCSF events go only to endpoints that name `ocsf.event` or `ocsf.*`. An endpoint subscribed to `*` does not receive them. The push carries the governance events stream. Project traces and the audit log are pulled.

## Pushing OCSF events into LangWatch

`POST /api/governance/ocsf/ingest` stores OCSF events from another tool, such as your identity provider or an AI platform's own audit feed, next to LangWatch's events:

```bash
curl -s "https://app.langwatch.ai/api/governance/ocsf/ingest" \
  -H "Authorization: Bearer $LANGWATCH_ORG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "source": "okta",
    "events": [
      {
        "class_uid": 3002,
        "activity_id": 1,
        "severity_id": 1,
        "time": 1763114521123,
        "metadata": { "uid": "okta-evt-1", "version": "1.4.0", "product": { "name": "Okta" } },
        "user": { "name": "jane@acme.com" }
      }
    ]
  }'
```

The answer is `{ "accepted": 1 }`. A request holds up to 500 events. Each needs `class_uid`, `severity_id`, `time` (epoch milliseconds) and `metadata.uid` and `metadata.version`, and is at most 64 KiB as JSON. An invalid event is a 422 naming the field.

An event is identified by `source` and `metadata.uid`: sending it again replaces the stored copy. Stored events are read back from `/events` with `source_type=ocsf_push`, exactly as received, and are not pushed to webhook endpoints.

## Session export

The tRPC query `governance.ocsfExport` still returns the governance events in their stored OCSF 1.1 row shape, for the signed-in UI. Use the REST routes above for a SIEM job.

**Also check:** [Anomaly rules](https://langwatch.ai/docs/ai-governance/anomaly-rules) for how a fired alert reaches you, and [Retention](https://langwatch.ai/docs/ai-gateway/governance/retention) for how long the source traces are kept.

## Read AI events from AWS Security Lake

LangWatch can subscribe to your AWS Security Lake and read the CloudTrail management and data events for Bedrock and SageMaker calls. Add a Security Lake source under Governance, Ingestion sources, with the subscriber role ARN, Region and queue URL that Security Lake gave you when you created the subscriber.

LangWatch generates the source's external id when you add it. You can't choose it. Copy it from the source's edit form, or read it from the API, and set it as the `sts:ExternalId` condition in the subscriber role's trust policy. The trust policy must require it, or any LangWatch customer that knows the role ARN could ask LangWatch to assume your role.

LangWatch reads each Parquet object the queue announces, keeps the model, agent and endpoint calls, and deletes the message only after the events are written. A message that keeps failing is recorded as poison once it passes its receive limit.

### Minimal IAM for the subscriber role

The access keys you store on the source are the base identity. That identity needs `sts:AssumeRole` on the subscriber role, and the role's trust policy must allow it only with the external id LangWatch generated as the `sts:ExternalId` condition. Before each read, LangWatch assumes the subscriber role with that external id and reads the queue and the bucket with the role's temporary credentials.

The subscriber role needs only these permissions:

- `s3:GetObject` on the Security Lake bucket prefix of the selected sources.
- `sqs:ReceiveMessage`, `sqs:DeleteMessage`, `sqs:ChangeMessageVisibility` and `sqs:GetQueueAttributes` on the subscriber queue. LangWatch extends a message's visibility while it reads the file. The connection test uses `sqs:GetQueueAttributes`.
- `kms:Decrypt` on the lake key, only when the lake uses a customer managed KMS key.

### Callers without traces

The source page lists the principals that called a model in the last 30 days and sent no traces. A principal counts as traced when a trace in any project of the organisation carries its ARN in the `aws.principal.arn` attribute.

> ## 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.
