| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
- import { APIResource } from "../../core/resource.mjs";
- import { Page } from "../../core/pagination.mjs";
- import { buildHeaders } from "../../internal/headers.mjs";
- import { stainlessHelperHeaderFromFile } from "../../lib/stainless-helper-header.mjs";
- import { multipartFormRequestOptions } from "../../internal/uploads.mjs";
- import { path } from "../../internal/utils/path.mjs";
- export class Files extends APIResource {
- /**
- * List Files
- *
- * @example
- * ```ts
- * // Automatically fetches more pages as needed.
- * for await (const fileMetadata of client.beta.files.list()) {
- * // ...
- * }
- * ```
- */
- list(params = {}, options) {
- const { betas, ...query } = params ?? {};
- return this._client.getAPIList('/v1/files', (Page), {
- query,
- ...options,
- headers: buildHeaders([
- { 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
- options?.headers,
- ]),
- });
- }
- /**
- * Delete File
- *
- * @example
- * ```ts
- * const deletedFile = await client.beta.files.delete(
- * 'file_id',
- * );
- * ```
- */
- delete(fileID, params = {}, options) {
- const { betas } = params ?? {};
- return this._client.delete(path `/v1/files/${fileID}`, {
- ...options,
- headers: buildHeaders([
- { 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
- options?.headers,
- ]),
- });
- }
- /**
- * Download File
- *
- * @example
- * ```ts
- * const response = await client.beta.files.download(
- * 'file_id',
- * );
- *
- * const content = await response.blob();
- * console.log(content);
- * ```
- */
- download(fileID, params = {}, options) {
- const { betas } = params ?? {};
- return this._client.get(path `/v1/files/${fileID}/content`, {
- ...options,
- headers: buildHeaders([
- {
- 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString(),
- Accept: 'application/binary',
- },
- options?.headers,
- ]),
- __binaryResponse: true,
- });
- }
- /**
- * Get File Metadata
- *
- * @example
- * ```ts
- * const fileMetadata =
- * await client.beta.files.retrieveMetadata('file_id');
- * ```
- */
- retrieveMetadata(fileID, params = {}, options) {
- const { betas } = params ?? {};
- return this._client.get(path `/v1/files/${fileID}`, {
- ...options,
- headers: buildHeaders([
- { 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
- options?.headers,
- ]),
- });
- }
- /**
- * Upload File
- *
- * @example
- * ```ts
- * const fileMetadata = await client.beta.files.upload({
- * file: fs.createReadStream('path/to/file'),
- * });
- * ```
- */
- upload(params, options) {
- const { betas, ...body } = params;
- return this._client.post('/v1/files', multipartFormRequestOptions({
- body,
- ...options,
- headers: buildHeaders([
- { 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
- stainlessHelperHeaderFromFile(body.file),
- options?.headers,
- ]),
- }, this._client));
- }
- }
- //# sourceMappingURL=files.mjs.map
|