Creates a new B2Client. Call authorize before making API requests.
Configuration including credentials, realm, and transport settings.
ReadonlyaccountAuthorization state storage (tokens, URLs, capabilities).
ReadonlyrawLow-level client for direct B2 API calls.
ReadonlyurlSSRF allow-list applied by the default FetchTransport. null when
a custom transport was supplied — in that case the SDK does not own the
guard. Locked down by B2Client.authorize.
Authenticates with B2 and stores the authorization state. Must be called before other methods.
The authorization response containing tokens, URLs, and capabilities.
Creates a new B2 bucket.
Bucket configuration including name, type, and optional settings.
OptionalbucketInfo?: Record<string, string>Custom key-value metadata stored with the bucket.
Globally unique bucket name (6-50 chars, letters, digits, hyphens).
Access level: "allPrivate" or "allPublic".
OptionalcorsRules?: CorsRule[]CORS rules for browser-based access.
OptionaldefaultRetention?: BucketRetentionPolicyDefault retention policy for new files (requires file lock).
OptionaldefaultServerSideEncryption?: EncryptionSettingDefault server-side encryption for new files.
OptionalfileLockEnabled?: booleanEnable file lock (Object Lock) on the bucket. Cannot be disabled once set.
OptionallifecycleRules?: LifecycleRule[]Lifecycle rules for automatic file deletion or hiding.
OptionalreplicationConfiguration?: ReplicationConfigurationCross-region replication configuration.
A Bucket handle for the newly created bucket.
Creates a new application key with the specified capabilities.
Key configuration including capabilities, name, and optional restrictions.
OptionalbucketId?: BucketIdRestrict the key to a single bucket.
Capabilities to grant (e.g., ["readFiles", "writeFiles"]).
Human-readable name for the key.
OptionalnamePrefix?: stringRestrict the key to files with this name prefix.
OptionalvalidDurationInSeconds?: numberKey expiration in seconds from now. Omit for non-expiring keys.
The full key including the secret (only returned at creation time).
Permanently deletes a bucket. The bucket must be empty.
The unique identifier of the bucket to delete.
The deleted bucket metadata.
Permanently deletes an application key.
The unique identifier of the key to delete.
The deleted application key metadata.
Checks whether the authorized application key carries every capability in
needed. Returns the missing capabilities so callers can fail fast with a
clear error instead of a generic 401/403 from the server.
The capabilities required by the planned operation.
An object with ok: true when every needed capability is
present, otherwise { ok: false, missing: [...] }.
If authorize has not been called yet.
Lists buckets in the account, optionally filtered by ID, name, or type.
Optionaloptions: { bucketId?: BucketId; bucketName?: string; bucketTypes?: BucketType[] }Optional filters for bucket ID, name, or type.
OptionalbucketId?: BucketIdFilter to a specific bucket by ID.
OptionalbucketName?: stringFilter to a specific bucket by name.
OptionalbucketTypes?: BucketType[]Filter by bucket types (e.g., ["allPrivate"]).
An array of Bucket handles.
Lists application keys in the account.
Optionaloptions: { pageSize?: number; startApplicationKeyId?: ApplicationKeyId }Optional pagination settings.
OptionalpageSize?: numberMaximum number of keys to return per request. Forwarded to the
raw API's maxKeyCount parameter.
OptionalstartApplicationKeyId?: ApplicationKeyIdStart listing after this key ID (for pagination).
A page of application keys with an optional continuation token.
Async iterator that yields every application key on the account,
automatically handling pagination via listKeys.
Optionaloptions: PaginatorOptionsPagination + abort options. pageSize is forwarded
to maxKeyCount; the default is 1000.
An async iterable of ApplicationKey entries.
High-level B2 client providing ergonomic access to buckets, files, and keys.
Example