api-promise.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { type OpenAI } from "../client.js";
  2. import { type PromiseOrValue } from "../internal/types.js";
  3. import { type APIResponseProps, type WithRequestID } from "../internal/parse.js";
  4. /**
  5. * A subclass of `Promise` providing additional helper methods
  6. * for interacting with the SDK.
  7. */
  8. export declare class APIPromise<T> extends Promise<WithRequestID<T>> {
  9. #private;
  10. private responsePromise;
  11. private parseResponse;
  12. private parsedPromise;
  13. constructor(client: OpenAI, responsePromise: Promise<APIResponseProps>, parseResponse?: (client: OpenAI, props: APIResponseProps) => PromiseOrValue<WithRequestID<T>>);
  14. _thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U>;
  15. /**
  16. * Gets the raw `Response` instance instead of parsing the response
  17. * data.
  18. *
  19. * If you want to parse the response body but still get the `Response`
  20. * instance, you can use {@link withResponse()}.
  21. *
  22. * 👋 Getting the wrong TypeScript type for `Response`?
  23. * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
  24. * to your `tsconfig.json`.
  25. */
  26. asResponse(): Promise<Response>;
  27. /**
  28. * Gets the parsed response data, the raw `Response` instance and the ID of the request,
  29. * returned via the X-Request-ID header which is useful for debugging requests and reporting
  30. * issues to OpenAI.
  31. *
  32. * If you just want to get the raw `Response` instance without parsing it,
  33. * you can use {@link asResponse()}.
  34. *
  35. * 👋 Getting the wrong TypeScript type for `Response`?
  36. * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
  37. * to your `tsconfig.json`.
  38. */
  39. withResponse(): Promise<{
  40. data: T;
  41. response: Response;
  42. request_id: string | null;
  43. }>;
  44. private parse;
  45. then<TResult1 = WithRequestID<T>, TResult2 = never>(onfulfilled?: ((value: WithRequestID<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
  46. catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<WithRequestID<T> | TResult>;
  47. finally(onfinally?: (() => void) | undefined | null): Promise<WithRequestID<T>>;
  48. }
  49. //# sourceMappingURL=api-promise.d.ts.map