# tode.init()

Initialize Tode in your Figma plugin's controller code (`code.ts`). Nothing is sent until it has run.

## Usage

```typescript title="code.ts"
import { tode } from '@tode-sdk/core';

await tode.init({
  apiKey: 'your-api-key',
  debug: false
});
```

## Parameters

| Option | Type | Required | Description |
|--------|------|----------|-------------|
| `apiKey` | `string` | Yes | Your Tode API key |
| `debug` | `boolean` | No | Enable debug logging (default: false) |
| `apiUrl` | `string` | No | HTTP endpoint for events (default: `https://processing.usetode.dev`) |
| `wsUrl` | `string` | No | WebSocket endpoint for sessions (default: `wss://processing.usetode.dev`) |
| `signal` | `AbortSignal` | No | Cancel `init()` early. Requests time out after 10 seconds on their own |

## Returns

`Promise<void>`

## Notes

- This method must be called from the plugin controller (where `figma` global is available), not from the UI
- Events tracked before `init()` finishes are held (up to 50) and sent when it does; `await` it before `figma.closePlugin()` so they get out
- Never throws: called from the UI by mistake, it logs an error and returns
- Only call once per plugin session

## Example

```typescript title="code.ts"
import { tode } from '@tode-sdk/core';

// Show your UI
figma.showUI(__html__, { width: 400, height: 600 });

// Initialize Tode
await tode.init({ apiKey: 'your-api-key' });

// Now you can track actions
tode.trackAction('plugin_opened');
```

## See Also

- [tode.trackAction()](https://docs.usetode.dev/api/track-action) - Track simple actions
- [tode.isReady](https://docs.usetode.dev/api/is-ready) - Check initialization status

Source: https://docs.usetode.dev/api/init
