|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import { APIResource } from '../core/resource'; |
| 4 | +import { APIPromise } from '../core/api-promise'; |
| 5 | +import { type Uploadable } from '../core/uploads'; |
| 6 | +import { buildHeaders } from '../internal/headers'; |
| 7 | +import { RequestOptions } from '../internal/request-options'; |
| 8 | +import { multipartFormRequestOptions } from '../internal/uploads'; |
| 9 | +import { path } from '../internal/utils/path'; |
| 10 | + |
| 11 | +export class Uploads extends APIResource { |
| 12 | + /** |
| 13 | + * Initiate an upload session with specified file metadata |
| 14 | + */ |
| 15 | + create(params: UploadCreateParams, options?: RequestOptions): APIPromise<UploadCreateResponse> { |
| 16 | + const { 'X-API-Version': xAPIVersion, ...body } = params; |
| 17 | + return this._client.post('/uploads', { |
| 18 | + body, |
| 19 | + ...options, |
| 20 | + headers: buildHeaders([ |
| 21 | + { ...(xAPIVersion?.toString() != null ? { 'X-API-Version': xAPIVersion?.toString() } : undefined) }, |
| 22 | + options?.headers, |
| 23 | + ]), |
| 24 | + }); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Get the status of the given upload session |
| 29 | + */ |
| 30 | + get( |
| 31 | + uploadID: string, |
| 32 | + params: UploadGetParams | null | undefined = {}, |
| 33 | + options?: RequestOptions, |
| 34 | + ): APIPromise<UploadGetResponse> { |
| 35 | + const { 'X-API-Version': xAPIVersion } = params ?? {}; |
| 36 | + return this._client.get(path`/uploads/${uploadID}`, { |
| 37 | + ...options, |
| 38 | + headers: buildHeaders([ |
| 39 | + { ...(xAPIVersion?.toString() != null ? { 'X-API-Version': xAPIVersion?.toString() } : undefined) }, |
| 40 | + options?.headers, |
| 41 | + ]), |
| 42 | + }); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Upload a chunk of bytes to the upload session |
| 47 | + */ |
| 48 | + part(uploadID: string, params: UploadPartParams, options?: RequestOptions): APIPromise<UploadPartResponse> { |
| 49 | + const { 'X-API-Version': xAPIVersion, 'X-Upload-Offset': xUploadOffset, ...body } = params; |
| 50 | + return this._client.post( |
| 51 | + path`/uploads/${uploadID}`, |
| 52 | + multipartFormRequestOptions( |
| 53 | + { |
| 54 | + body, |
| 55 | + ...options, |
| 56 | + headers: buildHeaders([ |
| 57 | + { |
| 58 | + ...(xAPIVersion?.toString() != null ? { 'X-API-Version': xAPIVersion?.toString() } : undefined), |
| 59 | + ...(xUploadOffset?.toString() != null ? |
| 60 | + { 'X-Upload-Offset': xUploadOffset?.toString() } |
| 61 | + : undefined), |
| 62 | + }, |
| 63 | + options?.headers, |
| 64 | + ]), |
| 65 | + }, |
| 66 | + this._client, |
| 67 | + ), |
| 68 | + ); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +export interface UploadCreateResponse { |
| 73 | + /** |
| 74 | + * The unique upload session identifier to use for uploading the file |
| 75 | + */ |
| 76 | + id: string; |
| 77 | + |
| 78 | + /** |
| 79 | + * The number of bytes in the file you are uploading |
| 80 | + */ |
| 81 | + bytes: number; |
| 82 | + |
| 83 | + /** |
| 84 | + * The name of the file to upload |
| 85 | + */ |
| 86 | + filename: string; |
| 87 | + |
| 88 | + /** |
| 89 | + * The MIME type of the file. Must be one of the supported MIME type for the given |
| 90 | + * purpose. |
| 91 | + */ |
| 92 | + mime_type: |
| 93 | + | 'image/jpeg' |
| 94 | + | 'image/jpg' |
| 95 | + | 'image/png' |
| 96 | + | 'image/gif' |
| 97 | + | 'image/webp' |
| 98 | + | 'image/x-icon' |
| 99 | + | 'audio/mp3' |
| 100 | + | 'audio/mpeg' |
| 101 | + | 'audio/wav' |
| 102 | + | 'audio/x-wav' |
| 103 | + | 'application/jsonl' |
| 104 | + | 'application/json' |
| 105 | + | 'text/plain' |
| 106 | + | 'video/mp4' |
| 107 | + | 'application/pdf'; |
| 108 | + |
| 109 | + /** |
| 110 | + * Intended purpose of the uploaded file. |
| 111 | + */ |
| 112 | + purpose: |
| 113 | + | 'attachment' |
| 114 | + | 'ephemeral_attachment' |
| 115 | + | 'image_generation_result' |
| 116 | + | 'messages_finetune' |
| 117 | + | 'messages_eval' |
| 118 | + | 'metadata'; |
| 119 | +} |
| 120 | + |
| 121 | +export interface UploadGetResponse { |
| 122 | + /** |
| 123 | + * The unique upload session identifier to use for uploading the file |
| 124 | + */ |
| 125 | + upload_id: string; |
| 126 | + |
| 127 | + /** |
| 128 | + * This is a zero-based numeric index of byte number in which the current upload |
| 129 | + * session to be resuming upload from |
| 130 | + */ |
| 131 | + offset?: number; |
| 132 | +} |
| 133 | + |
| 134 | +export interface UploadPartResponse { |
| 135 | + /** |
| 136 | + * The unique upload session identifier to use for uploading the file |
| 137 | + */ |
| 138 | + upload_id: string; |
| 139 | + |
| 140 | + /** |
| 141 | + * The ready file identifier after the upload is complete |
| 142 | + */ |
| 143 | + file_id?: string; |
| 144 | + |
| 145 | + /** |
| 146 | + * This is a zero-based numeric index of byte number in which the current upload |
| 147 | + * session to be resuming upload from |
| 148 | + */ |
| 149 | + offset?: number; |
| 150 | +} |
| 151 | + |
| 152 | +export interface UploadCreateParams { |
| 153 | + /** |
| 154 | + * Body param: The number of bytes in the file you are uploading |
| 155 | + */ |
| 156 | + bytes: number; |
| 157 | + |
| 158 | + /** |
| 159 | + * Body param: The name of the file to upload |
| 160 | + */ |
| 161 | + filename: string; |
| 162 | + |
| 163 | + /** |
| 164 | + * Body param: The MIME type of the file. Must be one of the supported MIME type |
| 165 | + * for the given purpose. |
| 166 | + */ |
| 167 | + mime_type: |
| 168 | + | 'image/jpeg' |
| 169 | + | 'image/jpg' |
| 170 | + | 'image/png' |
| 171 | + | 'image/gif' |
| 172 | + | 'image/webp' |
| 173 | + | 'image/x-icon' |
| 174 | + | 'audio/mp3' |
| 175 | + | 'audio/mpeg' |
| 176 | + | 'audio/wav' |
| 177 | + | 'audio/x-wav' |
| 178 | + | 'application/jsonl' |
| 179 | + | 'application/json' |
| 180 | + | 'text/plain' |
| 181 | + | 'video/mp4' |
| 182 | + | 'application/pdf'; |
| 183 | + |
| 184 | + /** |
| 185 | + * Body param: Intended purpose of the uploaded file. |
| 186 | + */ |
| 187 | + purpose: |
| 188 | + | 'attachment' |
| 189 | + | 'ephemeral_attachment' |
| 190 | + | 'image_generation_result' |
| 191 | + | 'messages_finetune' |
| 192 | + | 'messages_eval' |
| 193 | + | 'metadata'; |
| 194 | + |
| 195 | + /** |
| 196 | + * Header param: |
| 197 | + */ |
| 198 | + 'X-API-Version'?: '1.0.0'; |
| 199 | +} |
| 200 | + |
| 201 | +export interface UploadGetParams { |
| 202 | + 'X-API-Version'?: '1.0.0'; |
| 203 | +} |
| 204 | + |
| 205 | +export interface UploadPartParams { |
| 206 | + /** |
| 207 | + * Body param: The chunk of bytes to upload |
| 208 | + */ |
| 209 | + data: Uploadable; |
| 210 | + |
| 211 | + /** |
| 212 | + * Header param: |
| 213 | + */ |
| 214 | + 'X-API-Version'?: '1.0.0'; |
| 215 | + |
| 216 | + /** |
| 217 | + * Header param: The offset of the chunk of bytes to upload for the upload session |
| 218 | + */ |
| 219 | + 'X-Upload-Offset'?: number; |
| 220 | +} |
| 221 | + |
| 222 | +export declare namespace Uploads { |
| 223 | + export { |
| 224 | + type UploadCreateResponse as UploadCreateResponse, |
| 225 | + type UploadGetResponse as UploadGetResponse, |
| 226 | + type UploadPartResponse as UploadPartResponse, |
| 227 | + type UploadCreateParams as UploadCreateParams, |
| 228 | + type UploadGetParams as UploadGetParams, |
| 229 | + type UploadPartParams as UploadPartParams, |
| 230 | + }; |
| 231 | +} |
0 commit comments