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

# TypeScript

> Call Operational Evidence from a server-side TypeScript application.

# TypeScript example

The following example uses the standard `fetch` API.

Run this code only in a trusted server-side environment.

Do not expose `THE_WO_API_KEY` in browser or mobile application bundles.

## Environment variables

```bash theme={null}
export THE_WO_API_BASE_URL="<your-api-base-url>"
export THE_WO_API_KEY="<your-api-key>"
```

Use the API base URL assigned to your environment by The Wo.

A public production hostname is not documented until that environment is
available.

## Example

```ts theme={null}
interface OperationalReportResult {
  readonly title: string;
  readonly description: string;
  readonly category:
    | "plumbing"
    | "electrical"
    | "cleaning"
    | "security"
    | "elevator"
    | "structural"
    | "appliance"
    | "other";
  readonly priority: "low" | "medium" | "high" | "urgent";
  readonly suggestedNextStep: string | null;
  readonly tags: readonly string[];
  readonly riskFlags: readonly string[];
  readonly confidence: number;
}

interface CreateEvidenceReportResponse {
  readonly id: string;
  readonly status: "completed";

  readonly result: OperationalReportResult;

  readonly usage: {
    readonly operation: "evidence_report";

    readonly units: 1;
  };
}

interface ApiErrorResponse {
  readonly error: {
    readonly code: string;
    readonly message: string;
    readonly requestId: string;

    readonly details?: Readonly<Record<string, string | number | boolean | null>>;
  };
}

const baseUrl = process.env.THE_WO_API_BASE_URL;

const apiKey = process.env.THE_WO_API_KEY;

if (!baseUrl || !apiKey) {
  throw new Error("THE_WO_API_BASE_URL and THE_WO_API_KEY are required.");
}

const response = await fetch(`${baseUrl}/v1/evidence/reports`, {
  method: "POST",

  headers: {
    "content-type": "application/json",

    "x-api-key": apiKey,
  },

  body: JSON.stringify({
    context: "property_maintenance",

    language: "en",

    evidence: {
      text: "Water is collecting under the bathroom sink.",

      images: [
        {
          url: "https://example.com/evidence/sink-leak.jpg",
        },
      ],
    },
  }),
});

const body = (await response.json()) as CreateEvidenceReportResponse | ApiErrorResponse;

if (!response.ok) {
  const apiError = body as ApiErrorResponse;

  console.error("The Wo request failed", {
    status: response.status,
    code: apiError.error.code,
    requestId: apiError.error.requestId,
  });

  throw new Error(apiError.error.message);
}

const report = body as CreateEvidenceReportResponse;

console.log(report.id, report.result.title, report.result.priority, report.usage);
```

## Important integration rules

Keep the API key server-side.

Use `error.code` for programmatic error handling instead of matching the
human-readable message.

Keep `error.requestId` when reporting failed requests.

Do not assume that a failed create request can always be retried
idempotently.

## Example quota handling

Applications may handle monthly quota exhaustion explicitly:

```ts theme={null}
if (!response.ok && response.status === 429) {
  const apiError = body as ApiErrorResponse;

  if (apiError.error.code === "quota_exceeded") {
    console.log("Monthly quota exhausted", apiError.error.details);
  }
}
```

See [Errors](/operational-evidence/guides/errors) and
[Usage and quotas](/operational-evidence/guides/usage-and-quotas) for the complete behavior.
