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

# SDK API

> Reference the frozen window.Totem methods injected into a published game.

export const LastVerified = ({date, source}) => <div className="totem-verified">
    <span>Last verified: {date}</span>
    {source ? <span>Source: {source}</span> : null}
  </div>;

export const StatusBadge = ({state = "available", children}) => {
  const labels = {
    available: "Available",
    "early-access": "Early access",
    planned: "Planned",
    internal: "Internal draft"
  };
  return <span className={`totem-status totem-status--${state}`}>
      {children || labels[state] || state}
    </span>;
};

<StatusBadge state="available" />

<LastVerified date="2026-08-14" source="Totem V1 contract" />

## `window.Totem`

`window.Totem` is frozen. Do not replace it or add properties.

```javascript theme={null}
Object.isFrozen(window.Totem) // true
```

## `gameOver({ score })`

Call this once when a run ends.

```javascript theme={null}
window.Totem.gameOver({ score: 12800 })
```

| Input   | Type   | Rules                                                                            |
| ------- | ------ | -------------------------------------------------------------------------------- |
| `score` | number | Must be finite. Zero and negative scores are accepted when the game allows them. |

An invalid score is ignored and writes a console warning. A valid call records a `game_over` event and asks the Totem shell to submit the score for the current player.

The shell can reject a score above the game's configured maximum or more than one score from the same player and game within ten seconds. The game-over screen still keeps Play again available.

## `event(name, props)`

Record a game-specific custom event.

```javascript theme={null}
window.Totem.event("level_complete", {
  level: 4,
  elapsed_s: 36
})
```

`props` must be JSON-serializable. One event payload can be at most 2,048 bytes. Do not include secrets or direct personal information.

## Safe fallback

```javascript theme={null}
window.Totem?.gameOver({ score })
```

This lets the same build run outside a Totem play page.
