The @tauri-apps/api package is the primary TypeScript/JavaScript interface that frontend applications use to interact with Tauri's Rust backend. This package provides type-safe bindings for invoking backend commands, managing windows and webviews, handling events, and accessing other platform capabilities. It serves as the developer-facing API layer that abstracts the underlying IPC communication mechanisms.
This page covers the overall architecture and organization of the @tauri-apps/api package. For detailed information about specific aspects:
For information about how this package fits into the broader frontend-backend communication architecture, see IPC and Frontend-Backend Communication.
The @tauri-apps/api package is published as an npm package with dual ESM/CJS output formats and full TypeScript support. The package is versioned independently from the Tauri core runtime and follows semantic versioning.
Package Metadata:
| Property | Value |
|---|---|
| Package Name | @tauri-apps/api |
| Current Version | 2.11.1 |
| Main Entry (CJS) | ./index.cjs |
| Module Entry (ESM) | ./index.js |
| TypeScript Types | ./index.d.ts |
| License | Apache-2.0 OR MIT |
The package uses a modular export structure where each module can be imported individually.
Sources: packages/api/package.json1-37
The API package is organized into focused modules, each providing functionality for a specific domain. The core module contains the fundamental IPC primitives like invoke and Channel.
Sources: packages/api/package.json25-36 packages/api/src/core.ts1-260
The @tauri-apps/api package serves as the bridge between frontend application code and the Tauri runtime. It relies on the __TAURI_INTERNALS__ object injected into the webview to perform actual IPC operations.
Sources: packages/api/src/core.ts77-154 crates/tauri/src/ipc/channel.rs132-195 crates/tauri/scripts/bundle.global.js20-55
The package uses Rollup for bundling with TypeScript compilation. The build process generates multiple output formats to support different module systems.
Build Configuration:
| Aspect | Configuration |
|---|---|
| Bundler | Rollup 4.62.0 |
| TypeScript | 6.0.2 |
| Minification | @rollup/plugin-terser 1.0.0 |
| Output Formats | ESM (.js), CJS (.cjs), TypeScript (.d.ts) |
| Build Command | rollup -c --configPlugin typescript |
Sources: packages/api/package.json39-62 pnpm-lock.yaml89-97
The package is part of the larger Tauri monorepo workspace. During development, examples link directly to the built artifacts.
Sources: packages/api/package.json41-42 examples/api/package.json12-14 pnpm-lock.yaml27-29
Frontend applications declare @tauri-apps/api as a dependency and import required modules. The invoke function is the primary way to trigger Rust logic, while the Channel class handles streaming data.
Sources: packages/api/src/core.ts77-154 packages/api/src/core.ts251-257
The package includes strict linting and type checking to ensure API stability and security.
Quality Tools:
eslint 10.0.2 with eslint-plugin-securitytypescript 6.0.2 for static analysisprettier for consistent formattingSources: packages/api/package.json43-45 packages/api/package.json53-61 package.json27-29