export type CreateApiV1ChatCompletionsArgs = {body: {metadata?: ({[key: string]: unknown} | unknown) | undefined, top_logprobs?: (number | null) | undefined, temperature?: (number | unknown) | undefined, top_p?: (number | unknown) | undefined, top_k?: (number | unknown) | undefined, user?: string | undefined, safety_identifier?: string | undefined, prompt_cache_key?: string | undefined, cache_control?: ({type?: 'ephemeral' | undefined, ttl?: string | undefined}) | undefined, service_tier?: ('auto' | 'default' | 'flex' | 'scale' | 'priority' | unknown) | undefined, messages: Array<{content: string | Array<{type: 'text', text: string}>, role: 'developer', name?: string | undefined} | {content: string | Array<{type: 'text', text: string}>, role: 'system', name?: string | undefined} | {content: string | Array<{type: 'text', text: string} | {type: 'image_url', image_url: {url: string, detail?: ('auto' | 'low' | 'high') | undefined}} | {type: 'document', source: {type: 'text', media_type: string, data: string}, title?: string | undefined, citations?: {enabled: boolean} | undefined}>, role: 'user', name?: string | undefined} | {content?: (string | Array<{type: 'text', text: string} | {type: 'refusal', refusal: string}> | unknown) | undefined, refusal?: (string | unknown) | undefined, role: 'assistant', name?: string | undefined, audio?: ({id: string} | unknown) | undefined, tool_calls?: (Array<{id: string, type: 'function', function: {name: string, arguments: string}} | {id: string, type: 'custom', custom: {name: string, input: string}}>) | undefined, function_call?: ({arguments: string, name: string} | unknown) | undefined} | {role: 'tool', content: string | Array<{type: 'text', text: string}>, tool_call_id: string} | {role: 'function', content: string | unknown, name: string}>, model: string, modalities?: (Array<'text'> | unknown) | undefined, verbosity?: ('low' | 'medium' | 'high' | unknown) | undefined, reasoning_effort?: ('minimal' | 'low' | 'medium' | 'high' | unknown) | undefined, reasoning_options?: {budget_tokens: number} | undefined, max_completion_tokens?: (number | null) | undefined, frequency_penalty?: (number | null) | undefined, presence_penalty?: (number | null) | undefined, response_format?: ({type: 'text'} | {type: 'json_schema', json_schema: {description?: string | undefined, name: string, schema?: Record | undefined, strict?: (boolean | unknown) | undefined}} | {type: 'json_object'}) | undefined, store?: (boolean | null) | undefined, stream?: (boolean | null) | undefined, stop?: (string | Array | null) | undefined, logit_bias?: ({[key: string]: number} | null) | undefined, logprobs?: (boolean | null) | undefined, max_tokens?: (number | null) | undefined, n?: (number | null) | undefined, prediction?: ({type: 'content', content: string | Array<{type: 'text', text: string}>, reasoning?: string | undefined} | null) | undefined, seed?: (number | null) | undefined, stream_options?: ({include_usage?: boolean | undefined, include_obfuscation?: boolean | undefined} | unknown) | undefined, tools?: (Array<{type: 'function', function: {description?: string | undefined, name: string, parameters?: Record | undefined, strict?: (boolean | unknown) | undefined}} | {type: 'custom', custom: {name: string, description?: string | undefined, format?: ({type: 'text'} | {type: 'grammar', grammar: {definition: string, syntax: 'lark' | 'regex'}}) | undefined}}>) | undefined, tool_choice?: ('none' | 'auto' | 'required' | {type: 'allowed_tools', allowed_tools: {mode: 'auto' | 'required', tools: Array>}} | {type: 'function', function: {name: string}} | {type: 'custom', custom: {name: string}}) | undefined, parallel_tool_calls?: boolean | undefined, function_call?: ('none' | 'auto' | {name: string}) | undefined, functions?: (Array<{description?: string | undefined, name: string, parameters?: Record | undefined}>) | undefined, context_editing?: ({enabled: boolean, clear_tool_uses?: ({trigger?: number | undefined, keep?: number | undefined, clear_at_least?: number | undefined, exclude_tools?: Array | undefined, clear_tool_inputs?: boolean | undefined}) | undefined, clear_thinking?: ({keep?: (number | 'all') | undefined}) | undefined}) | undefined, image_generation?: {aspect_ratio: string, image_size: string} | undefined}}; export type CreateApiV1ChatCompletionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create Chat Completion * * POST /v1/chat/completions */ export const createApiV1ChatCompletions = async (args: CreateApiV1ChatCompletionsArgs, options?: CreateApiV1ChatCompletionsOptions) => { const {baseUrl = "https://ai-gateway.helicone.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/chat/completions${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 undefined };