Skip to main content
Serve mode runs the Bitwarden CLI as a RESTful API web server, enabling programmatic access to vault operations through HTTP endpoints.

Starting the Server

You must be logged in before starting serve mode. The vault can be locked or unlocked.

Options

string
Hostname to bind the API server to (default: localhost)Use all for no hostname binding (bind to all interfaces).
number
Port to run the API server on (default: 8087)
boolean
Allow requests with Origin header
This option exists for backwards compatibility and exposes your environment to known CSRF attacks. Use with caution.

Examples

Server Configuration

When serve mode starts, it automatically sets:
These ensure commands run non-interactively and format responses appropriately for API consumption.

Origin Protection

By default, the server blocks requests with an Origin header to prevent CSRF attacks:
To disable this protection (not recommended):

Advanced Hostname Options

Serve mode supports several hostname formats: File descriptor (connected socket):
File descriptor (listening socket):
Unix domain socket:

API Endpoints

All endpoints return JSON responses. Most require an unlocked vault.

Status and Authentication

GET /status

Get server and vault status.
Response:

POST /unlock

Unlock the vault.
Response:
For security, passwordFile and passwordEnv query parameters are blocked in serve mode.

POST /lock

Lock the vault.

POST /sync

Sync vault data from server.

Vault Object Operations

GET /list/object/:object

List vault objects. Parameters:
  • :object - Object type: items, folders, collections, org-collections, org-members, organizations, send
Query parameters:
  • search - Search filter
  • url - URL filter (for items)
  • folderid - Folder ID filter
  • collectionid - Collection ID filter
  • organizationid - Organization ID filter
  • trash - Show trash items (boolean)
  • archived - Show archived items (boolean, requires feature flag)
Response:

GET /object/:object/:id

Get a specific object. Parameters:
  • :object - Object type: item, folder, collection, org-collection, organization, send
  • :id - Object ID or search term
Query parameters:
  • itemid - Item ID (for attachments)
  • organizationid - Organization ID (for org objects)

POST /object/:object

Create a new object. Parameters:
  • :object - Object type: item, folder, org-collection, send
Body: JSON or base64-encoded JSON object Query parameters:
  • organizationid - Organization ID (for org objects)

PUT /object/:object/:id

Update an existing object. Parameters:
  • :object - Object type: item, folder, org-collection, send
  • :id - Object ID
Body: JSON or base64-encoded JSON with updates

DELETE /object/:object/:id

Delete an object. Parameters:
  • :object - Object type: item, folder, org-collection, send
  • :id - Object ID
Query parameters:
  • itemid - Item ID (for attachments)
  • organizationid - Organization ID (for org objects)
  • permanent - Permanently delete (boolean, for items)

Attachments

POST /attachment

Create an attachment. Content-Type: multipart/form-data Form fields:
  • file - File to upload
  • itemid - Item ID to attach to

Send Operations

GET /send/list

List all Sends.

POST /send/:id/remove-password

Remove password from a Send. Parameters:
  • :id - Send ID

Organization Operations

POST /move/:id/:organizationId

Move item to organization. Parameters:
  • :id - Item ID
  • :organizationId - Organization ID
Body: Array of collection IDs (JSON or base64-encoded)

POST /confirm/:object/:id

Confirm organization member. Parameters:
  • :object - Object type (currently only org-member)
  • :id - Member ID
Query parameters:
  • organizationid - Organization ID (required)

POST /restore/:object/:id

Restore item from trash or archive. Parameters:
  • :object - Object type (currently only item)
  • :id - Item ID

POST /archive/:object/:id

Archive an item. Parameters:
  • :object - Object type (currently only item)
  • :id - Item ID
Requires PM19148_InnovationArchive feature flag.

Utilities

GET /generate

Generate password or passphrase. Query parameters:
  • uppercase - Include uppercase (boolean)
  • lowercase - Include lowercase (boolean)
  • number - Include numbers (boolean)
  • special - Include special chars (boolean)
  • passphrase - Generate passphrase (boolean)
  • length - Password length (number)
  • words - Passphrase words (number)
  • separator - Word separator (string)
  • capitalize - Capitalize words (boolean)
  • includeNumber - Include number in passphrase (boolean)

Response Format

All endpoints return a consistent response structure:

Success Response

Error Response

HTTP Status Codes:
  • 200 OK - Success
  • 400 Bad Request - Error (vault locked, invalid input, etc.)
  • 403 Forbidden - Origin protection violation

Locked Vault Errors

Endpoints that require an unlocked vault return:
HTTP Status: 400

Not Logged In Errors

HTTP Status: 400

Environment Variables

Serve mode automatically sets:
string
Always set to "true" in serve mode
string
Always set to "true" to disable interactive prompts
string
Commands respect this for JSON formatting
You can still use other environment variables like BW_SESSION when starting the server.

Usage Examples

Complete Workflow

Python Client Example

JavaScript/Node.js Example

Security Considerations

Serve mode provides network access to your vault. Follow these security practices:
  1. Bind to localhost: Default localhost binding ensures only local access
  2. Use HTTPS reverse proxy: For remote access, use nginx/Apache with TLS
  3. Enable origin protection: Keep --disable-origin-protection disabled
  4. Network isolation: Run on isolated networks or use firewall rules
  5. Lock when done: Always lock the vault after operations
  6. Avoid public exposure: Never expose serve mode directly to the internet

Reverse Proxy Example (nginx)

Architecture

Serve mode is implemented with:
  • Koa: Web framework (src/commands/serve.command.ts:31)
  • @koa/router: Routing (oss-serve-configurator.ts:221-439)
  • koa-bodyparser: JSON body parsing
  • koa-json: JSON response formatting
  • @koa/multer: Multipart form data (attachments)
Endpoint configuration is in src/oss-serve-configurator.ts, which can be extended by commercial builds.

Next Steps

Commands Reference

Full CLI commands documentation

Overview

CLI overview and installation