export type CreateApiV1ChatCompletionsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * OpenAI Chat Completions 兼容入口 * * POST /v1/chat/completions */ export const createApiV1ChatCompletions = async (options: CreateApiV1ChatCompletionsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() const url = `${baseUrl.replace(/\/+$/, '')}/v1/chat/completions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };