export type CreateApiApiV1IndexIndexIdDocArgs = {apikey: string, index_id: number, body: {[key: string]: unknown}}; export type CreateApiApiV1IndexIndexIdDocOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Index Document(s) * * POST /api/v1/index/{index_id}/doc */ export const createApiApiV1IndexIndexIdDoc = async (args: CreateApiApiV1IndexIndexIdDocArgs, options?: CreateApiApiV1IndexIndexIdDocOptions) => { const {baseUrl = "http://127.0.0.1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (args.apikey != null) headers.set("apikey", String(args.apikey)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/index/${encodeURIComponent(String(args.index_id))}/doc${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };