"use strict";
// This file was auto-generated by Fern from our API Definition.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CohereClient = void 0;
const Cohere = __importStar(require("./api/index"));
const Client_1 = require("./api/resources/batches/client/Client");
const Client_2 = require("./api/resources/connectors/client/Client");
const Client_3 = require("./api/resources/datasets/client/Client");
const Client_4 = require("./api/resources/embedJobs/client/Client");
const Client_5 = require("./api/resources/finetuning/client/Client");
const Client_6 = require("./api/resources/models/client/Client");
const Client_7 = require("./api/resources/v2/client/Client");
const core = __importStar(require("./core"));
const headers_1 = require("./core/headers");
const environments = __importStar(require("./environments"));
const errors = __importStar(require("./errors/index"));
const serializers = __importStar(require("./serialization/index"));
class CohereClient {
    constructor(_options = {}) {
        this._options = Object.assign(Object.assign({}, _options), { logging: core.logging.createLogger(_options === null || _options === void 0 ? void 0 : _options.logging), headers: (0, headers_1.mergeHeaders)({
                "X-Client-Name": _options === null || _options === void 0 ? void 0 : _options.clientName,
                "X-Fern-Language": "JavaScript",
                "X-Fern-SDK-Name": "cohere-ai",
                "X-Fern-SDK-Version": "7.20.0",
                "User-Agent": "cohere-ai/7.20.0",
                "X-Fern-Runtime": core.RUNTIME.type,
                "X-Fern-Runtime-Version": core.RUNTIME.version,
            }, _options === null || _options === void 0 ? void 0 : _options.headers) });
    }
    get v2() {
        var _a;
        return ((_a = this._v2) !== null && _a !== void 0 ? _a : (this._v2 = new Client_7.V2(this._options)));
    }
    get batches() {
        var _a;
        return ((_a = this._batches) !== null && _a !== void 0 ? _a : (this._batches = new Client_1.Batches(this._options)));
    }
    get embedJobs() {
        var _a;
        return ((_a = this._embedJobs) !== null && _a !== void 0 ? _a : (this._embedJobs = new Client_4.EmbedJobs(this._options)));
    }
    get datasets() {
        var _a;
        return ((_a = this._datasets) !== null && _a !== void 0 ? _a : (this._datasets = new Client_3.Datasets(this._options)));
    }
    get connectors() {
        var _a;
        return ((_a = this._connectors) !== null && _a !== void 0 ? _a : (this._connectors = new Client_2.Connectors(this._options)));
    }
    get models() {
        var _a;
        return ((_a = this._models) !== null && _a !== void 0 ? _a : (this._models = new Client_6.Models(this._options)));
    }
    get finetuning() {
        var _a;
        return ((_a = this._finetuning) !== null && _a !== void 0 ? _a : (this._finetuning = new Client_5.Finetuning(this._options)));
    }
    /**
     * Generates a streamed text response to a user message.
     *
     * To learn how to use the Chat API and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
     */
    chatStream(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__chatStream(request, requestOptions));
    }
    __chatStream(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const { accepts } = request, _body = __rest(request, ["accepts"]);
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                Accepts: accepts != null ? accepts : undefined,
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/chat"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: Object.assign(Object.assign({}, serializers.ChatStreamRequest.jsonOrThrow(_body, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                })), { stream: true }),
                responseType: "sse",
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: new core.Stream({
                        stream: _response.body,
                        parse: (data) => __awaiter(this, void 0, void 0, function* () {
                            return serializers.StreamedChatResponse.parseOrThrow(data, {
                                unrecognizedObjectKeys: "passthrough",
                                allowUnrecognizedUnionMembers: true,
                                allowUnrecognizedEnumValues: true,
                                skipValidation: true,
                                breadcrumbsPrefix: ["response"],
                            });
                        }),
                        signal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                        eventShape: {
                            type: "json",
                            messageTerminator: "\n",
                        },
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/chat.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Generates a text response to a user message.
     * To learn how to use the Chat API and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api).
     *
     * @param {Cohere.ChatRequest} request
     * @param {CohereClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.UnprocessableEntityError}
     * @throws {@link Cohere.TooManyRequestsError}
     * @throws {@link Cohere.InvalidTokenError}
     * @throws {@link Cohere.ClientClosedRequestError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.NotImplementedError}
     * @throws {@link Cohere.ServiceUnavailableError}
     * @throws {@link Cohere.GatewayTimeoutError}
     *
     * @example
     *     await client.chat({
     *         model: "command-a-03-2025",
     *         message: "Tell me about LLMs"
     *     })
     *
     * @example
     *     await client.chat({
     *         model: "command-a-03-2025",
     *         message: "Who is more popular: Nsync or Backstreet Boys?",
     *         documents: [{
     *                 "title": "CSPC: Backstreet Boys Popularity Analysis - ChartMasters",
     *                 "snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: Backstreet Boys Popularity Analysis\n\nHern\u00E1n Lopez Posted on February 9, 2017 Posted in CSPC 72 Comments Tagged with Backstreet Boys, Boy band\n\nAt one point, Backstreet Boys defined success: massive albums sales across the globe, great singles sales, plenty of chart topping releases, hugely hyped tours and tremendous media coverage.\n\nIt is true that they benefited from extraordinarily good market conditions in all markets. After all, the all-time record year for the music business, as far as revenues in billion dollars are concerned, was actually 1999. That is, back when this five men group was at its peak."
     *             }, {
     *                 "title": "CSPC: NSYNC Popularity Analysis - ChartMasters",
     *                 "snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: NSYNC Popularity Analysis\n\nMJD Posted on February 9, 2018 Posted in CSPC 27 Comments Tagged with Boy band, N'Sync\n\nAt the turn of the millennium three teen acts were huge in the US, the Backstreet Boys, Britney Spears and NSYNC. The latter is the only one we haven\u2019t study so far. It took 15 years and Adele to break their record of 2,4 million units sold of No Strings Attached in its first week alone.\n\nIt wasn\u2019t a fluke, as the second fastest selling album of the Soundscan era prior 2015, was also theirs since Celebrity debuted with 1,88 million units sold."
     *             }, {
     *                 "title": "CSPC: Backstreet Boys Popularity Analysis - ChartMasters",
     *                 "snippet": "1997, 1998, 2000 and 2001 also rank amongst some of the very best years.\nYet the way many music consumers \u2013 especially teenagers and young women\u2019s \u2013 embraced their output deserves its own chapter. If Jonas Brothers and more recently One Direction reached a great level of popularity during the past decade, the type of success achieved by Backstreet Boys is in a completely different level as they really dominated the business for a few years all over the world, including in some countries that were traditionally hard to penetrate for Western artists.\n\nWe will try to analyze the extent of that hegemony with this new article with final results which will more than surprise many readers."
     *             }, {
     *                 "title": "CSPC: NSYNC Popularity Analysis - ChartMasters",
     *                 "snippet": "Was the teen group led by Justin Timberlake really that big? Was it only in the US where they found success? Or were they a global phenomenon?\nAs usual, I\u2019ll be using the Commensurate Sales to Popularity Concept in order to relevantly gauge their results. This concept will not only bring you sales information for all NSYNC\u2018s albums, physical and download singles, as well as audio and video streaming, but it will also determine their true popularity. If you are not yet familiar with the CSPC method, the next page explains it with a short video. I fully recommend watching the video before getting into the sales figures."
     *             }]
     *     })
     *
     * @example
     *     await client.chat({
     *         model: "command-a-03-2025",
     *         message: "Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?",
     *         tools: [{
     *                 name: "query_daily_sales_report",
     *                 description: "Connects to a database to retrieve overall sales volumes and sales information for a given day.",
     *                 parameterDefinitions: {
     *                     "day": {
     *                         description: "Retrieves sales data for this day, formatted as YYYY-MM-DD.",
     *                         type: "str",
     *                         required: true
     *                     }
     *                 }
     *             }, {
     *                 name: "query_product_catalog",
     *                 description: "Connects to a a product catalog with information about all the products being sold, including categories, prices, and stock levels.",
     *                 parameterDefinitions: {
     *                     "category": {
     *                         description: "Retrieves product information data for all products in this category.",
     *                         type: "str",
     *                         required: true
     *                     }
     *                 }
     *             }]
     *     })
     */
    chat(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__chat(request, requestOptions));
    }
    __chat(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const { accepts } = request, _body = __rest(request, ["accepts"]);
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                Accepts: accepts != null ? accepts : undefined,
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/chat"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: Object.assign(Object.assign({}, serializers.ChatRequest.jsonOrThrow(_body, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                })), { stream: false }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.NonStreamedChatResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/chat.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * <Warning>
     * This API is marked as "Legacy" and is no longer maintained. Follow the [migration guide](https://docs.cohere.com/docs/migrating-from-cogenerate-to-cochat) to start using the Chat with Streaming API.
     * </Warning>
     * Generates realistic text conditioned on a given input.
     */
    generateStream(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__generateStream(request, requestOptions));
    }
    __generateStream(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/generate"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: Object.assign(Object.assign({}, serializers.GenerateStreamRequest.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                })), { stream: true }),
                responseType: "sse",
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: new core.Stream({
                        stream: _response.body,
                        parse: (data) => __awaiter(this, void 0, void 0, function* () {
                            return serializers.GenerateStreamedResponse.parseOrThrow(data, {
                                unrecognizedObjectKeys: "passthrough",
                                allowUnrecognizedUnionMembers: true,
                                allowUnrecognizedEnumValues: true,
                                skipValidation: true,
                                breadcrumbsPrefix: ["response"],
                            });
                        }),
                        signal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                        eventShape: {
                            type: "json",
                            messageTerminator: "\n",
                        },
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/generate.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * <Warning>
     * This API is marked as "Legacy" and is no longer maintained. Follow the [migration guide](https://docs.cohere.com/docs/migrating-from-cogenerate-to-cochat) to start using the Chat API.
     * </Warning>
     * Generates realistic text conditioned on a given input.
     *
     * @param {Cohere.GenerateRequest} request
     * @param {CohereClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.UnprocessableEntityError}
     * @throws {@link Cohere.TooManyRequestsError}
     * @throws {@link Cohere.InvalidTokenError}
     * @throws {@link Cohere.ClientClosedRequestError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.NotImplementedError}
     * @throws {@link Cohere.ServiceUnavailableError}
     * @throws {@link Cohere.GatewayTimeoutError}
     *
     * @example
     *     await client.generate({
     *         prompt: "Please explain to me how LLMs work"
     *     })
     */
    generate(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__generate(request, requestOptions));
    }
    __generate(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/generate"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: Object.assign(Object.assign({}, serializers.GenerateRequest.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                })), { stream: false }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.Generation.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/generate.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * This endpoint returns text and image embeddings. An embedding is a list of floating point numbers that captures semantic information about the content that it represents.
     *
     * Embeddings can be used to create classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
     *
     * If you want to learn more how to use the embedding model, have a look at the [Semantic Search Guide](https://docs.cohere.com/docs/semantic-search).
     *
     * @param {Cohere.EmbedRequest} request
     * @param {CohereClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.UnprocessableEntityError}
     * @throws {@link Cohere.TooManyRequestsError}
     * @throws {@link Cohere.InvalidTokenError}
     * @throws {@link Cohere.ClientClosedRequestError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.NotImplementedError}
     * @throws {@link Cohere.ServiceUnavailableError}
     * @throws {@link Cohere.GatewayTimeoutError}
     *
     * @example
     *     await client.embed({
     *         texts: ["hello", "goodbye"],
     *         model: "embed-v4.0",
     *         inputType: "classification"
     *     })
     *
     * @example
     *     await client.embed({
     *         model: "embed-v4.0",
     *         inputType: "image",
     *         embeddingTypes: ["float"],
     *         images: ["data:image/jpeg;base64, "]
     *     })
     */
    embed(request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__embed(request, requestOptions));
    }
    __embed() {
        return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/embed"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: serializers.EmbedRequest.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.EmbedResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/embed.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * This endpoint takes in a query and a list of texts and produces an ordered array with each text assigned a relevance score.
     *
     * @param {Cohere.RerankRequest} request
     * @param {CohereClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.UnprocessableEntityError}
     * @throws {@link Cohere.TooManyRequestsError}
     * @throws {@link Cohere.InvalidTokenError}
     * @throws {@link Cohere.ClientClosedRequestError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.NotImplementedError}
     * @throws {@link Cohere.ServiceUnavailableError}
     * @throws {@link Cohere.GatewayTimeoutError}
     *
     * @example
     *     await client.rerank({
     *         documents: [{
     *                 "text": "Carson City is the capital city of the American state of Nevada."
     *             }, {
     *                 "text": "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan."
     *             }, {
     *                 "text": "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages."
     *             }, {
     *                 "text": "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district."
     *             }, {
     *                 "text": "Capital punishment has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
     *             }],
     *         query: "What is the capital of the United States?",
     *         topN: 3,
     *         model: "rerank-v3.5"
     *     })
     */
    rerank(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__rerank(request, requestOptions));
    }
    __rerank(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/rerank"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: serializers.RerankRequest.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.RerankResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/rerank.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * This endpoint makes a prediction about which label fits the specified text inputs best. To make a prediction, Classify uses the provided `examples` of text + label pairs as a reference.
     * Note: [Fine-tuned models](https://docs.cohere.com/docs/classify-fine-tuning) trained on classification examples don't require the `examples` parameter to be passed in explicitly.
     *
     * @param {Cohere.ClassifyRequest} request
     * @param {CohereClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.UnprocessableEntityError}
     * @throws {@link Cohere.TooManyRequestsError}
     * @throws {@link Cohere.InvalidTokenError}
     * @throws {@link Cohere.ClientClosedRequestError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.NotImplementedError}
     * @throws {@link Cohere.ServiceUnavailableError}
     * @throws {@link Cohere.GatewayTimeoutError}
     *
     * @example
     *     await client.classify({
     *         examples: [{
     *                 text: "Dermatologists don't like her!",
     *                 label: "Spam"
     *             }, {
     *                 text: "'Hello, open to this?'",
     *                 label: "Spam"
     *             }, {
     *                 text: "I need help please wire me $1000 right now",
     *                 label: "Spam"
     *             }, {
     *                 text: "Nice to know you ;)",
     *                 label: "Spam"
     *             }, {
     *                 text: "Please help me?",
     *                 label: "Spam"
     *             }, {
     *                 text: "Your parcel will be delivered today",
     *                 label: "Not spam"
     *             }, {
     *                 text: "Review changes to our Terms and Conditions",
     *                 label: "Not spam"
     *             }, {
     *                 text: "Weekly sync notes",
     *                 label: "Not spam"
     *             }, {
     *                 text: "'Re: Follow up from today's meeting'",
     *                 label: "Not spam"
     *             }, {
     *                 text: "Pre-read for tomorrow",
     *                 label: "Not spam"
     *             }],
     *         inputs: ["Confirm your email address", "hey i need u to send some $"],
     *         model: "YOUR-FINE-TUNED-MODEL-ID"
     *     })
     */
    classify(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__classify(request, requestOptions));
    }
    __classify(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/classify"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: serializers.ClassifyRequest.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.ClassifyResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/classify.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * <Warning>
     * This API is marked as "Legacy" and is no longer maintained. Follow the [migration guide](https://docs.cohere.com/docs/migrating-from-cogenerate-to-cochat) to start using the Chat API.
     * </Warning>
     * Generates a summary in English for a given text.
     *
     * @param {Cohere.SummarizeRequest} request
     * @param {CohereClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.UnprocessableEntityError}
     * @throws {@link Cohere.TooManyRequestsError}
     * @throws {@link Cohere.InvalidTokenError}
     * @throws {@link Cohere.ClientClosedRequestError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.NotImplementedError}
     * @throws {@link Cohere.ServiceUnavailableError}
     * @throws {@link Cohere.GatewayTimeoutError}
     *
     * @example
     *     await client.summarize({
     *         text: "Ice cream is a sweetened frozen food typically eaten as a snack or dessert. It may be made from milk or cream and is flavoured with a sweetener, either sugar or an alternative, and a spice, such as cocoa or vanilla, or with fruit such as strawberries or peaches. It can also be made by whisking a flavored cream base and liquid nitrogen together. Food coloring is sometimes added, in addition to stabilizers. The mixture is cooled below the freezing point of water and stirred to incorporate air spaces and to prevent detectable ice crystals from forming. The result is a smooth, semi-solid foam that is solid at very low temperatures (below 2 \u00B0C or 35 \u00B0F). It becomes more malleable as its temperature increases.\n\nThe meaning of the name \"ice cream\" varies from one country to another. In some countries, such as the United States, \"ice cream\" applies only to a specific variety, and most governments regulate the commercial use of the various terms according to the relative quantities of the main ingredients, notably the amount of cream. Products that do not meet the criteria to be called ice cream are sometimes labelled \"frozen dairy dessert\" instead. In other countries, such as Italy and Argentina, one word is used fo\r all variants. Analogues made from dairy alternatives, such as goat's or sheep's milk, or milk substitutes (e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are lactose intolerant, allergic to dairy protein or vegan."
     *     })
     */
    summarize(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__summarize(request, requestOptions));
    }
    __summarize(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/summarize"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: serializers.SummarizeRequest.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.SummarizeResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/summarize.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * This endpoint splits input text into smaller units called tokens using byte-pair encoding (BPE). To learn more about tokenization and byte pair encoding, see the tokens page.
     *
     * @param {Cohere.TokenizeRequest} request
     * @param {CohereClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.UnprocessableEntityError}
     * @throws {@link Cohere.TooManyRequestsError}
     * @throws {@link Cohere.InvalidTokenError}
     * @throws {@link Cohere.ClientClosedRequestError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.NotImplementedError}
     * @throws {@link Cohere.ServiceUnavailableError}
     * @throws {@link Cohere.GatewayTimeoutError}
     *
     * @example
     *     await client.tokenize({
     *         text: "tokenize me! :D",
     *         model: "command"
     *     })
     */
    tokenize(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__tokenize(request, requestOptions));
    }
    __tokenize(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/tokenize"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: serializers.TokenizeRequest.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.TokenizeResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/tokenize.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * This endpoint takes tokens using byte-pair encoding and returns their text representation. To learn more about tokenization and byte pair encoding, see the tokens page.
     *
     * @param {Cohere.DetokenizeRequest} request
     * @param {CohereClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.UnprocessableEntityError}
     * @throws {@link Cohere.TooManyRequestsError}
     * @throws {@link Cohere.InvalidTokenError}
     * @throws {@link Cohere.ClientClosedRequestError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.NotImplementedError}
     * @throws {@link Cohere.ServiceUnavailableError}
     * @throws {@link Cohere.GatewayTimeoutError}
     *
     * @example
     *     await client.detokenize({
     *         tokens: [10002, 2261, 2012, 8, 2792, 43],
     *         model: "command"
     *     })
     */
    detokenize(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__detokenize(request, requestOptions));
    }
    __detokenize(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/detokenize"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: serializers.DetokenizeRequest.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.DetokenizeResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/detokenize.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Checks that the api key in the Authorization header is valid and active
     *
     * @param {CohereClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.UnprocessableEntityError}
     * @throws {@link Cohere.TooManyRequestsError}
     * @throws {@link Cohere.InvalidTokenError}
     * @throws {@link Cohere.ClientClosedRequestError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.NotImplementedError}
     * @throws {@link Cohere.ServiceUnavailableError}
     * @throws {@link Cohere.GatewayTimeoutError}
     *
     * @example
     *     await client.checkApiKey()
     */
    checkApiKey(requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__checkApiKey(requestOptions));
    }
    __checkApiKey(requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/check-api-key"),
                method: "POST",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.CheckApiKeyResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 422:
                        throw new Cohere.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    case 429:
                        throw new Cohere.TooManyRequestsError(_response.error.body, _response.rawResponse);
                    case 498:
                        throw new Cohere.InvalidTokenError(_response.error.body, _response.rawResponse);
                    case 499:
                        throw new Cohere.ClientClosedRequestError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 501:
                        throw new Cohere.NotImplementedError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    case 504:
                        throw new Cohere.GatewayTimeoutError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/check-api-key.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    _getAuthorizationHeader() {
        return __awaiter(this, void 0, void 0, function* () {
            var _a;
            const bearer = (_a = (yield core.Supplier.get(this._options.token))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env.CO_API_KEY;
            if (bearer != null) {
                return `Bearer ${bearer}`;
            }
            return undefined;
        });
    }
}
exports.CohereClient = CohereClient;
