/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { OpenAIRequestMessage, OpenAIRequestMessage$inboundSchema, OpenAIRequestMessage$Outbound, OpenAIRequestMessage$outboundSchema, } from "./openairequestmessage.js"; import { OpenAIToolDefinition, OpenAIToolDefinition$inboundSchema, OpenAIToolDefinition$Outbound, OpenAIToolDefinition$outboundSchema, } from "./openaitooldefinition.js"; /** * The function to call */ export type ToolChoiceFunction = { /** * The name of the function to call */ name: string; }; /** * Forces the model to call a specific function */ export type Four = { /** * The type of the tool. Currently only 'function' is supported. */ type: "function"; /** * The function to call */ function: ToolChoiceFunction; }; /** * Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. */ export type Stop = string | Array; export const Type2 = { Text: "text", JsonObject: "json_object", } as const; export type Type2 = ClosedEnum; /** * The format type. Use 'json_object' to enable JSON mode, guaranteeing the message the model generates is valid JSON. */ export type OpenAIChatCompletionRequestParamsType = string | Type2; /** * JSON Schema definition for structured output. Required when type is 'json_schema'. */ export type JsonSchema = { name: string; schema: { [k: string]: any }; strict?: boolean | undefined; }; /** * An object specifying the format that the model must output. Setting to { 'type': 'json_object' } enables JSON mode. */ export type OpenAIChatCompletionRequestParamsResponseFormat = { /** * The format type. Use 'json_object' to enable JSON mode, guaranteeing the message the model generates is valid JSON. */ type: string | Type2; /** * JSON Schema definition for structured output. Required when type is 'json_schema'. */ jsonSchema?: JsonSchema | undefined; }; /** * Options for streaming response. Only set this when you set stream: true. */ export type StreamOptions = { /** * If set, an additional chunk with token usage statistics will be streamed before the data: [DONE] message. The usage field shows total token usage for the entire request. */ includeUsage?: boolean | undefined; }; export const ReasoningEffort = { None: "none", Minimal: "minimal", Low: "low", Medium: "medium", High: "high", Xhigh: "xhigh", } as const; export type ReasoningEffort = ClosedEnum; /** * Request parameters for creating a chat completion. Based on the OpenAI Chat Completions API. */ export type OpenAIChatCompletionRequestParams = { /** * ID of the model to use. You can use provider:model format or just the model name with a default provider. */ model: string; /** * A list of messages comprising the conversation so far. At least one message is required. */ messages: Array; /** * A list of tools the model may call. Use this to provide function definitions the model can invoke. */ tools?: Array | undefined; /** * Controls which (if any) tool is called by the model. 'none' means the model will not call any tool. 'auto' means the model can pick. 'required' forces a tool call. */ toolChoice?: any | undefined; /** * If set, partial message deltas will be sent as server-sent events. Note: This field is ignored by the streaming endpoint, used only by OpenAI-compatible client endpoints. */ stream?: boolean | undefined; /** * How many chat completion choices to generate for each input message. Default is 1. */ n?: number | undefined; /** * The maximum number of tokens that can be generated in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. */ maxTokens?: number | undefined; /** * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. */ temperature?: number | undefined; /** * An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. */ topP?: number | undefined; /** * Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. */ frequencyPenalty?: number | undefined; /** * Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. */ presencePenalty?: number | undefined; /** * If specified, the system will make a best effort to sample deterministically. Determinism is not guaranteed, but the same seed should typically return similar results. */ seed?: number | undefined; /** * Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. */ stop?: string | Array | undefined; /** * An object specifying the format that the model must output. Setting to { 'type': 'json_object' } enables JSON mode. */ responseFormat?: OpenAIChatCompletionRequestParamsResponseFormat | undefined; /** * Whether to return log probabilities of the output tokens. If true, returns the log probabilities of each output token returned in the content of message. */ logprobs?: boolean | undefined; /** * An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used. */ topLogprobs?: number | undefined; /** * A unique identifier representing your end-user, which can help monitor and detect abuse. Also used for usage tracking and analytics. */ user?: string | undefined; /** * Options for streaming response. Only set this when you set stream: true. */ streamOptions?: StreamOptions | undefined; /** * Whether to enable parallel function calling during tool use. */ parallelToolCalls?: boolean | undefined; /** * Constrains effort on reasoning for reasoning models. Lower effort results in faster responses and fewer reasoning tokens. Supported values: 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', or null. */ reasoningEffort?: ReasoningEffort | null | undefined; /** * When true, the gateway analyzes request complexity and automatically routes between quantized, MoE, and dense variants of the requested model family. */ autoRouting?: boolean | undefined; }; /** @internal */ export const ToolChoiceFunction$inboundSchema: z.ZodType< ToolChoiceFunction, z.ZodTypeDef, unknown > = z.object({ name: z.string(), }); /** @internal */ export type ToolChoiceFunction$Outbound = { name: string; }; /** @internal */ export const ToolChoiceFunction$outboundSchema: z.ZodType< ToolChoiceFunction$Outbound, z.ZodTypeDef, ToolChoiceFunction > = z.object({ name: z.string(), }); export function toolChoiceFunctionToJSON( toolChoiceFunction: ToolChoiceFunction, ): string { return JSON.stringify( ToolChoiceFunction$outboundSchema.parse(toolChoiceFunction), ); } export function toolChoiceFunctionFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ToolChoiceFunction$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ToolChoiceFunction' from JSON`, ); } /** @internal */ export const Four$inboundSchema: z.ZodType = z .object({ type: z.literal("function"), function: z.lazy(() => ToolChoiceFunction$inboundSchema), }); /** @internal */ export type Four$Outbound = { type: "function"; function: ToolChoiceFunction$Outbound; }; /** @internal */ export const Four$outboundSchema: z.ZodType = z.object({ type: z.literal("function"), function: z.lazy(() => ToolChoiceFunction$outboundSchema), }); export function fourToJSON(four: Four): string { return JSON.stringify(Four$outboundSchema.parse(four)); } export function fourFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Four$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Four' from JSON`, ); } /** @internal */ export const Stop$inboundSchema: z.ZodType = z .union([z.string(), z.array(z.string())]); /** @internal */ export type Stop$Outbound = string | Array; /** @internal */ export const Stop$outboundSchema: z.ZodType = z.union([z.string(), z.array(z.string())]); export function stopToJSON(stop: Stop): string { return JSON.stringify(Stop$outboundSchema.parse(stop)); } export function stopFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Stop$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Stop' from JSON`, ); } /** @internal */ export const Type2$inboundSchema: z.ZodNativeEnum = z.nativeEnum( Type2, ); /** @internal */ export const Type2$outboundSchema: z.ZodNativeEnum = Type2$inboundSchema; /** @internal */ export const OpenAIChatCompletionRequestParamsType$inboundSchema: z.ZodType< OpenAIChatCompletionRequestParamsType, z.ZodTypeDef, unknown > = z.union([z.string(), Type2$inboundSchema]); /** @internal */ export type OpenAIChatCompletionRequestParamsType$Outbound = string | string; /** @internal */ export const OpenAIChatCompletionRequestParamsType$outboundSchema: z.ZodType< OpenAIChatCompletionRequestParamsType$Outbound, z.ZodTypeDef, OpenAIChatCompletionRequestParamsType > = z.union([z.string(), Type2$outboundSchema]); export function openAIChatCompletionRequestParamsTypeToJSON( openAIChatCompletionRequestParamsType: OpenAIChatCompletionRequestParamsType, ): string { return JSON.stringify( OpenAIChatCompletionRequestParamsType$outboundSchema.parse( openAIChatCompletionRequestParamsType, ), ); } export function openAIChatCompletionRequestParamsTypeFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionRequestParamsType$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionRequestParamsType' from JSON`, ); } /** @internal */ export const JsonSchema$inboundSchema: z.ZodType< JsonSchema, z.ZodTypeDef, unknown > = z.object({ name: z.string(), schema: z.record(z.any()), strict: z.boolean().optional(), }); /** @internal */ export type JsonSchema$Outbound = { name: string; schema: { [k: string]: any }; strict?: boolean | undefined; }; /** @internal */ export const JsonSchema$outboundSchema: z.ZodType< JsonSchema$Outbound, z.ZodTypeDef, JsonSchema > = z.object({ name: z.string(), schema: z.record(z.any()), strict: z.boolean().optional(), }); export function jsonSchemaToJSON(jsonSchema: JsonSchema): string { return JSON.stringify(JsonSchema$outboundSchema.parse(jsonSchema)); } export function jsonSchemaFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => JsonSchema$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'JsonSchema' from JSON`, ); } /** @internal */ export const OpenAIChatCompletionRequestParamsResponseFormat$inboundSchema: z.ZodType< OpenAIChatCompletionRequestParamsResponseFormat, z.ZodTypeDef, unknown > = z.object({ type: z.union([z.string(), Type2$inboundSchema]), json_schema: z.lazy(() => JsonSchema$inboundSchema).optional(), }).transform((v) => { return remap$(v, { "json_schema": "jsonSchema", }); }); /** @internal */ export type OpenAIChatCompletionRequestParamsResponseFormat$Outbound = { type: string | string; json_schema?: JsonSchema$Outbound | undefined; }; /** @internal */ export const OpenAIChatCompletionRequestParamsResponseFormat$outboundSchema: z.ZodType< OpenAIChatCompletionRequestParamsResponseFormat$Outbound, z.ZodTypeDef, OpenAIChatCompletionRequestParamsResponseFormat > = z.object({ type: z.union([z.string(), Type2$outboundSchema]), jsonSchema: z.lazy(() => JsonSchema$outboundSchema).optional(), }).transform((v) => { return remap$(v, { jsonSchema: "json_schema", }); }); export function openAIChatCompletionRequestParamsResponseFormatToJSON( openAIChatCompletionRequestParamsResponseFormat: OpenAIChatCompletionRequestParamsResponseFormat, ): string { return JSON.stringify( OpenAIChatCompletionRequestParamsResponseFormat$outboundSchema.parse( openAIChatCompletionRequestParamsResponseFormat, ), ); } export function openAIChatCompletionRequestParamsResponseFormatFromJSON( jsonString: string, ): SafeParseResult< OpenAIChatCompletionRequestParamsResponseFormat, SDKValidationError > { return safeParse( jsonString, (x) => OpenAIChatCompletionRequestParamsResponseFormat$inboundSchema.parse( JSON.parse(x), ), `Failed to parse 'OpenAIChatCompletionRequestParamsResponseFormat' from JSON`, ); } /** @internal */ export const StreamOptions$inboundSchema: z.ZodType< StreamOptions, z.ZodTypeDef, unknown > = z.object({ include_usage: z.boolean().optional(), }).transform((v) => { return remap$(v, { "include_usage": "includeUsage", }); }); /** @internal */ export type StreamOptions$Outbound = { include_usage?: boolean | undefined; }; /** @internal */ export const StreamOptions$outboundSchema: z.ZodType< StreamOptions$Outbound, z.ZodTypeDef, StreamOptions > = z.object({ includeUsage: z.boolean().optional(), }).transform((v) => { return remap$(v, { includeUsage: "include_usage", }); }); export function streamOptionsToJSON(streamOptions: StreamOptions): string { return JSON.stringify(StreamOptions$outboundSchema.parse(streamOptions)); } export function streamOptionsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => StreamOptions$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'StreamOptions' from JSON`, ); } /** @internal */ export const ReasoningEffort$inboundSchema: z.ZodNativeEnum< typeof ReasoningEffort > = z.nativeEnum(ReasoningEffort); /** @internal */ export const ReasoningEffort$outboundSchema: z.ZodNativeEnum< typeof ReasoningEffort > = ReasoningEffort$inboundSchema; /** @internal */ export const OpenAIChatCompletionRequestParams$inboundSchema: z.ZodType< OpenAIChatCompletionRequestParams, z.ZodTypeDef, unknown > = z.object({ model: z.string(), messages: z.array(OpenAIRequestMessage$inboundSchema), tools: z.array(OpenAIToolDefinition$inboundSchema).optional(), tool_choice: z.any().optional(), stream: z.boolean().optional(), n: z.number().int().optional(), max_tokens: z.number().int().optional(), temperature: z.number().optional(), top_p: z.number().optional(), frequency_penalty: z.number().optional(), presence_penalty: z.number().optional(), seed: z.number().int().optional(), stop: z.union([z.string(), z.array(z.string())]).optional(), response_format: z.lazy(() => OpenAIChatCompletionRequestParamsResponseFormat$inboundSchema ).optional(), logprobs: z.boolean().optional(), top_logprobs: z.number().int().optional(), user: z.string().optional(), stream_options: z.lazy(() => StreamOptions$inboundSchema).optional(), parallel_tool_calls: z.boolean().default(true), reasoning_effort: z.nullable(ReasoningEffort$inboundSchema).optional(), auto_routing: z.boolean().optional(), }).transform((v) => { return remap$(v, { "tool_choice": "toolChoice", "max_tokens": "maxTokens", "top_p": "topP", "frequency_penalty": "frequencyPenalty", "presence_penalty": "presencePenalty", "response_format": "responseFormat", "top_logprobs": "topLogprobs", "stream_options": "streamOptions", "parallel_tool_calls": "parallelToolCalls", "reasoning_effort": "reasoningEffort", "auto_routing": "autoRouting", }); }); /** @internal */ export type OpenAIChatCompletionRequestParams$Outbound = { model: string; messages: Array; tools?: Array | undefined; tool_choice?: any | undefined; stream?: boolean | undefined; n?: number | undefined; max_tokens?: number | undefined; temperature?: number | undefined; top_p?: number | undefined; frequency_penalty?: number | undefined; presence_penalty?: number | undefined; seed?: number | undefined; stop?: string | Array | undefined; response_format?: | OpenAIChatCompletionRequestParamsResponseFormat$Outbound | undefined; logprobs?: boolean | undefined; top_logprobs?: number | undefined; user?: string | undefined; stream_options?: StreamOptions$Outbound | undefined; parallel_tool_calls: boolean; reasoning_effort?: string | null | undefined; auto_routing?: boolean | undefined; }; /** @internal */ export const OpenAIChatCompletionRequestParams$outboundSchema: z.ZodType< OpenAIChatCompletionRequestParams$Outbound, z.ZodTypeDef, OpenAIChatCompletionRequestParams > = z.object({ model: z.string(), messages: z.array(OpenAIRequestMessage$outboundSchema), tools: z.array(OpenAIToolDefinition$outboundSchema).optional(), toolChoice: z.any().optional(), stream: z.boolean().optional(), n: z.number().int().optional(), maxTokens: z.number().int().optional(), temperature: z.number().optional(), topP: z.number().optional(), frequencyPenalty: z.number().optional(), presencePenalty: z.number().optional(), seed: z.number().int().optional(), stop: z.union([z.string(), z.array(z.string())]).optional(), responseFormat: z.lazy(() => OpenAIChatCompletionRequestParamsResponseFormat$outboundSchema ).optional(), logprobs: z.boolean().optional(), topLogprobs: z.number().int().optional(), user: z.string().optional(), streamOptions: z.lazy(() => StreamOptions$outboundSchema).optional(), parallelToolCalls: z.boolean().default(true), reasoningEffort: z.nullable(ReasoningEffort$outboundSchema).optional(), autoRouting: z.boolean().optional(), }).transform((v) => { return remap$(v, { toolChoice: "tool_choice", maxTokens: "max_tokens", topP: "top_p", frequencyPenalty: "frequency_penalty", presencePenalty: "presence_penalty", responseFormat: "response_format", topLogprobs: "top_logprobs", streamOptions: "stream_options", parallelToolCalls: "parallel_tool_calls", reasoningEffort: "reasoning_effort", autoRouting: "auto_routing", }); }); export function openAIChatCompletionRequestParamsToJSON( openAIChatCompletionRequestParams: OpenAIChatCompletionRequestParams, ): string { return JSON.stringify( OpenAIChatCompletionRequestParams$outboundSchema.parse( openAIChatCompletionRequestParams, ), ); } export function openAIChatCompletionRequestParamsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIChatCompletionRequestParams$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIChatCompletionRequestParams' from JSON`, ); }