@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
266 lines • 9.74 kB
text/typescript
import { APIResource } from "../core/resource.mjs";
import { APIPromise } from "../core/api-promise.mjs";
import { BadRequestError, NotFoundError } from "../core/error.mjs";
import { PageCursor, type PageCursorParams, PagePromise } from "../core/pagination.mjs";
import { type Uploadable } from "../core/uploads.mjs";
import { RequestOptions } from "../internal/request-options.mjs";
/**
* The file has `downloadable: false`. Only files generated by a tool, such as the
* code execution tool, can be downloaded.
*/
export declare class FileNotDownloadableError extends BadRequestError {
readonly errorCode: 'file_not_downloadable';
readonly details: FileNotDownloadableErrorDetails;
}
/**
* The organization's file storage quota is exhausted. Delete files to free up
* space, then retry the upload.
*/
export declare class StorageQuotaExceededError extends BadRequestError {
readonly errorCode: 'storage_quota_exceeded';
readonly details: StorageQuotaExceededErrorDetails;
}
/**
* The file's `expires_at` has passed, so its content is no longer available.
*/
export declare class FileExpiredError extends NotFoundError {
readonly errorCode: 'file_expired';
readonly details: FileExpiredErrorDetails;
}
export declare class Files extends APIResource {
/**
* List Files
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {CMEKKeyDisabledError}
* @throws {CMEKKeyNetworkBlockedError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const fileMetadata of client.files.list()) {
* // ...
* }
* ```
*/
list(params?: FileListParams | null | undefined, options?: RequestOptions): PagePromise<FileMetadataPageCursor, FileMetadata>;
/**
* Delete File
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {CMEKKeyDisabledError}
* @throws {CMEKKeyNetworkBlockedError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* const deletedFile = await client.files.delete('file_id');
* ```
*/
delete(fileID: string, params?: FileDeleteParams | null | undefined, options?: RequestOptions): APIPromise<DeletedFile>;
/**
* Download File
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {CMEKKeyDisabledError}
* @throws {CMEKKeyNetworkBlockedError}
* @throws {FileNotDownloadableError}
* @throws {OrganizationOnHoldError}
* @throws {FileExpiredError}
*
* @example
* ```ts
* const response = await client.files.download('file_id');
*
* const content = await response.blob();
* console.log(content);
* ```
*/
download(fileID: string, params?: FileDownloadParams | null | undefined, options?: RequestOptions): APIPromise<Response>;
/**
* Get File Metadata
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {CMEKKeyDisabledError}
* @throws {CMEKKeyNetworkBlockedError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* const fileMetadata = await client.files.retrieveMetadata(
* 'file_id',
* );
* ```
*/
retrieveMetadata(fileID: string, params?: FileRetrieveMetadataParams | null | undefined, options?: RequestOptions): APIPromise<FileMetadata>;
/**
* Upload File
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {CMEKKeyDisabledError}
* @throws {CMEKKeyNetworkBlockedError}
* @throws {OrganizationOnHoldError}
* @throws {StorageQuotaExceededError}
*
* @example
* ```ts
* const fileMetadata = await client.files.upload({
* file: fs.createReadStream('path/to/file'),
* });
* ```
*/
upload(params: FileUploadParams, options?: RequestOptions): APIPromise<FileMetadata>;
}
export type FileMetadataPageCursor = PageCursor<FileMetadata>;
export interface DeletedFile {
/**
* ID of the deleted file.
*/
id: string;
/**
* Deleted object type.
*
* For file deletion, this is always `"file_deleted"`.
*/
type?: 'file_deleted';
}
/**
* The file's `expires_at` has passed, so its content is no longer available.
*/
export interface FileExpiredErrorDetails {
error_code: 'file_expired';
}
export interface FileMetadata {
/**
* Unique object identifier.
*
* The format and length of IDs may change over time.
*/
id: string;
/**
* RFC 3339 datetime string representing when the file was created.
*/
created_at: string;
/**
* Original filename of the uploaded file.
*/
filename: string;
/**
* MIME type of the file.
*/
mime_type: string;
/**
* Size of the file in bytes.
*/
size_bytes: number;
/**
* Object type.
*
* For files, this is always `"file"`.
*/
type: 'file';
/**
* Whether the file can be downloaded.
*/
downloadable?: boolean;
/**
* RFC 3339 datetime string representing when the file will expire and become
* unavailable for download. Null if the file does not expire. For files uploaded
* with `expires_in_seconds`, this is the upload time plus that value.
*/
expires_at?: string | null;
}
/**
* The file has `downloadable: false`. Only files generated by a tool, such as the
* code execution tool, can be downloaded.
*/
export interface FileNotDownloadableErrorDetails {
error_code: 'file_not_downloadable';
}
/**
* The organization's file storage quota is exhausted. Delete files to free up
* space, then retry the upload.
*/
export interface StorageQuotaExceededErrorDetails {
error_code: 'storage_quota_exceeded';
}
export interface FileListParams extends PageCursorParams {
/**
* Query param: Restrict the result set to Files whose `id` is in this list. At
* most 100 entries (after de-duplication). Mutually exclusive with `page` and
* `limit`. When supplied, the response is always a single page (`next_page` is
* null). IDs that do not resolve to a visible File — including deleted Files — are
* silently omitted.
*/
ids?: Array<string> | null;
/**
* Header param: Optional header to select the Workspace for this request. The
* value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
*
* Only needed for credentials that can act on more than one Workspace. A
* credential that belongs to a specific Workspace may omit it; if sent, it must
* match that Workspace.
*/
workspace_id?: string;
}
export interface FileDeleteParams {
/**
* Optional header to select the Workspace for this request. The value is a
* Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
*
* Only needed for credentials that can act on more than one Workspace. A
* credential that belongs to a specific Workspace may omit it; if sent, it must
* match that Workspace.
*/
workspace_id?: string;
}
export interface FileDownloadParams {
/**
* Optional header to select the Workspace for this request. The value is a
* Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
*
* Only needed for credentials that can act on more than one Workspace. A
* credential that belongs to a specific Workspace may omit it; if sent, it must
* match that Workspace.
*/
workspace_id?: string;
}
export interface FileRetrieveMetadataParams {
/**
* Optional header to select the Workspace for this request. The value is a
* Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
*
* Only needed for credentials that can act on more than one Workspace. A
* credential that belongs to a specific Workspace may omit it; if sent, it must
* match that Workspace.
*/
workspace_id?: string;
}
export interface FileUploadParams {
/**
* Body param: The file to upload. Only the final path component of the part's
* `filename` is kept; an absent or empty `filename` is replaced with `unnamed`
* plus the extension for the file's stored `mime_type`, when known.
*/
file: Uploadable;
/**
* Body param: Seconds from upload until the file expires and its bytes become
* permanently unavailable. Must be between 3600 (one hour) and 7776000 (ninety
* days).
*/
expires_in_seconds?: number;
/**
* Header param: Optional header to select the Workspace for this request. The
* value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
*
* Only needed for credentials that can act on more than one Workspace. A
* credential that belongs to a specific Workspace may omit it; if sent, it must
* match that Workspace.
*/
workspace_id?: string;
}
export declare namespace Files {
export { FileNotDownloadableError as FileNotDownloadableError, StorageQuotaExceededError as StorageQuotaExceededError, FileExpiredError as FileExpiredError, type DeletedFile as DeletedFile, type FileExpiredErrorDetails as FileExpiredErrorDetails, type FileMetadata as FileMetadata, type FileNotDownloadableErrorDetails as FileNotDownloadableErrorDetails, type StorageQuotaExceededErrorDetails as StorageQuotaExceededErrorDetails, type FileMetadataPageCursor as FileMetadataPageCursor, type FileListParams as FileListParams, type FileDeleteParams as FileDeleteParams, type FileDownloadParams as FileDownloadParams, type FileRetrieveMetadataParams as FileRetrieveMetadataParams, type FileUploadParams as FileUploadParams, };
}
//# sourceMappingURL=files.d.mts.map