diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 465c3544..14dee448 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 8b6cd71c-ea04-44da-af45-e43968b5928d management: - docChecksum: 6676183700397400ca1cc3c4e2b3fa14 + docChecksum: 21d34ad219f16d5944497a609bd0c936 docVersion: 1.0.0 - speakeasyVersion: 1.648.1 + speakeasyVersion: 1.649.0 generationVersion: 2.739.1 - releaseVersion: 0.1.0 - configChecksum: d449583229f714111a3a63d351a07b1f + releaseVersion: 0.1.1 + configChecksum: c28c46b34a103eebef5cf4e55b42c8b7 repoURL: https://github.com/OpenRouterTeam/typescript-sdk.git installationURL: https://github.com/OpenRouterTeam/typescript-sdk published: true @@ -69,6 +69,7 @@ generatedFiles: - docs/models/chatmessagecontentitem.md - docs/models/chatmessagecontentitemaudio.md - docs/models/chatmessagecontentitemaudioformat.md + - docs/models/chatmessagecontentitemaudioinputaudio.md - docs/models/chatmessagecontentitemimage.md - docs/models/chatmessagecontentitemimagedetail.md - docs/models/chatmessagecontentitemtext.md @@ -136,7 +137,6 @@ generatedFiles: - docs/models/ignore.md - docs/models/imagegenerationstatus.md - docs/models/imageurl.md - - docs/models/inputaudio.md - docs/models/inputmodality.md - docs/models/inputtokensdetails.md - docs/models/instructtype.md @@ -301,17 +301,28 @@ generatedFiles: - docs/models/operations/createcoinbasechargedata.md - docs/models/operations/createcoinbasechargeresponse.md - docs/models/operations/createcoinbasechargesecurity.md + - docs/models/operations/createembeddingsdata.md + - docs/models/operations/createembeddingsprovider.md + - docs/models/operations/createembeddingsrequest.md + - docs/models/operations/createembeddingsresponse.md + - docs/models/operations/createembeddingsresponsebody.md - docs/models/operations/createkeysdata.md - docs/models/operations/createkeyslimitreset.md - docs/models/operations/createkeysrequest.md - docs/models/operations/createkeysresponse.md - docs/models/operations/createresponsesresponse.md - docs/models/operations/createresponsesresponsebody.md + - docs/models/operations/datacollection.md - docs/models/operations/deletekeysrequest.md - docs/models/operations/deletekeysresponse.md + - docs/models/operations/embedding.md + - docs/models/operations/encodingformat.md + - docs/models/operations/encodingformatbase64.md + - docs/models/operations/encodingformatfloat.md - docs/models/operations/exchangeauthcodeforapikeycodechallengemethod.md - docs/models/operations/exchangeauthcodeforapikeyrequest.md - docs/models/operations/exchangeauthcodeforapikeyresponse.md + - docs/models/operations/experimental.md - docs/models/operations/getcreditsresponse.md - docs/models/operations/getcurrentkeydata.md - docs/models/operations/getcurrentkeyresponse.md @@ -323,11 +334,14 @@ generatedFiles: - docs/models/operations/getkeyresponse.md - docs/models/operations/getmodelsrequest.md - docs/models/operations/getparametersdata.md + - docs/models/operations/getparametersprovider.md - docs/models/operations/getparametersrequest.md - docs/models/operations/getparametersresponse.md - docs/models/operations/getparameterssecurity.md - docs/models/operations/getuseractivityrequest.md - docs/models/operations/getuseractivityresponse.md + - docs/models/operations/ignore.md + - docs/models/operations/input.md - docs/models/operations/listdata.md - docs/models/operations/listendpointsrequest.md - docs/models/operations/listendpointsresponse.md @@ -337,10 +351,15 @@ generatedFiles: - docs/models/operations/listprovidersresponse.md - docs/models/operations/listrequest.md - docs/models/operations/listresponse.md + - docs/models/operations/maxprice.md - docs/models/operations/metadata.md - - docs/models/operations/provider.md + - docs/models/operations/objectembedding.md + - docs/models/operations/objectt.md + - docs/models/operations/only.md + - docs/models/operations/order.md - docs/models/operations/ratelimit.md - docs/models/operations/sendchatcompletionrequestresponse.md + - docs/models/operations/sort.md - docs/models/operations/supportedparameter.md - docs/models/operations/transferintent.md - docs/models/operations/updatekeysdata.md @@ -348,6 +367,7 @@ generatedFiles: - docs/models/operations/updatekeysrequest.md - docs/models/operations/updatekeysrequestbody.md - docs/models/operations/updatekeysresponse.md + - docs/models/operations/usage.md - docs/models/operations/web3data.md - docs/models/order.md - docs/models/outputitemimagegenerationcall.md @@ -395,6 +415,10 @@ generatedFiles: - docs/models/responseformatjsonschema.md - docs/models/responseformattextconfig.md - docs/models/responseformattextgrammar.md + - docs/models/responseinputaudio.md + - docs/models/responseinputaudioformat.md + - docs/models/responseinputaudioinputaudio.md + - docs/models/responseinputaudiotype.md - docs/models/responseinputfile.md - docs/models/responseinputfiletype.md - docs/models/responseinputimage.md @@ -493,6 +517,7 @@ generatedFiles: - docs/sdks/chat/README.md - docs/sdks/completions/README.md - docs/sdks/credits/README.md + - docs/sdks/embeddings/README.md - docs/sdks/endpoints/README.md - docs/sdks/generations/README.md - docs/sdks/models/README.md @@ -520,6 +545,7 @@ generatedFiles: - src/funcs/completionsGenerate.ts - src/funcs/creditsCreateCoinbaseCharge.ts - src/funcs/creditsGetCredits.ts + - src/funcs/embeddingsGenerate.ts - src/funcs/endpointsList.ts - src/funcs/endpointsListZdrEndpoints.ts - src/funcs/generationsGetGeneration.ts @@ -663,6 +689,7 @@ generatedFiles: - src/models/openresponseswebsearchtool.ts - src/models/operations/createauthkeyscode.ts - src/models/operations/createcoinbasecharge.ts + - src/models/operations/createembeddings.ts - src/models/operations/createkeys.ts - src/models/operations/createresponses.ts - src/models/operations/deletekeys.ts @@ -701,6 +728,7 @@ generatedFiles: - src/models/responseformatjsonschema.ts - src/models/responseformattextconfig.ts - src/models/responseformattextgrammar.ts + - src/models/responseinputaudio.ts - src/models/responseinputfile.ts - src/models/responseinputimage.ts - src/models/responseinputtext.ts @@ -747,6 +775,7 @@ generatedFiles: - src/react-query/completionsGenerate.ts - src/react-query/creditsCreateCoinbaseCharge.ts - src/react-query/creditsGetCredits.ts + - src/react-query/embeddingsGenerate.ts - src/react-query/endpointsList.ts - src/react-query/endpointsListZdrEndpoints.ts - src/react-query/generationsGetGeneration.ts @@ -764,6 +793,7 @@ generatedFiles: - src/sdk/chat.ts - src/sdk/completions.ts - src/sdk/credits.ts + - src/sdk/embeddings.ts - src/sdk/endpoints.ts - src/sdk/generations.ts - src/sdk/index.ts @@ -1400,14 +1430,14 @@ examples: createCompletions: speakeasy-default-create-completions: requestBody: - application/json: {"model": "Model T", "prompt": "", "stream": false} + application/json: {"prompt": "", "stream": false} responses: "200": application/json: {"id": "", "object": "text_completion", "created": 2021.59, "model": "Jetta", "choices": []} "400": - application/json: {"error": {"code": "", "message": "", "param": "", "type": ""}} + application/json: {"error": {"code": "", "message": ""}} "500": - application/json: {"error": {"code": "", "message": "", "param": "", "type": ""}} + application/json: {"error": {"code": "", "message": ""}} sendResponsesRequest: speakeasy-default-send-responses-request: requestBody: @@ -1422,14 +1452,14 @@ examples: sendChatCompletionRequest: speakeasy-default-send-chat-completion-request: requestBody: - application/json: {"messages": [], "model": "Charger", "stream": false} + application/json: {"messages": [], "stream": false} responses: "200": application/json: {"id": "", "choices": [], "created": 2736.96, "model": "Impala", "object": "chat.completion"} "400": - application/json: {"error": {"code": "", "message": "", "param": "", "type": ""}} + application/json: {"error": {"code": "", "message": ""}} "500": - application/json: {"error": {"code": "", "message": "", "param": "", "type": ""}} + application/json: {"error": {"code": "", "message": ""}} createApiAlphaResponses: speakeasy-default-create-api-alpha-responses: requestBody: @@ -1493,7 +1523,7 @@ examples: id: "" responses: "200": - application/json: {"data": {"id": "gen-3bhGkxlo4XFrqiabUM7NDtwDzWwG", "upstream_id": "chatcmpl-791bcf62-080e-4568-87d0-94c72e3b4946", "total_cost": 0.0015, "cache_discount": 0.0002, "upstream_inference_cost": 0.0012, "created_at": "2024-07-15T23:33:19.433273+00:00", "model": "sao10k/l3-stheno-8b", "app_id": 12345, "streamed": true, "cancelled": false, "provider_name": "Infermatic", "latency": 1250, "moderation_latency": 50, "generation_time": 1200, "finish_reason": "stop", "tokens_prompt": 10, "tokens_completion": 25, "native_tokens_prompt": 10, "native_tokens_completion": 25, "native_tokens_completion_images": 0, "native_tokens_reasoning": 5, "native_tokens_cached": 3, "num_media_prompt": 1, "num_input_audio_prompt": 0, "num_media_completion": 0, "num_search_results": 5, "origin": "https://openrouter.ai/", "usage": 0.0015, "is_byok": false, "native_finish_reason": "stop", "external_user": "user-123", "api_type": "completions"}} + application/json: {"data": {"id": "gen-3bhGkxlo4XFrqiabUM7NDtwDzWwG", "upstream_id": "chatcmpl-791bcf62-080e-4568-87d0-94c72e3b4946", "total_cost": 0.0015, "cache_discount": 0.0002, "upstream_inference_cost": 0.0012, "created_at": "2024-07-15T23:33:19.433273+00:00", "model": "sao10k/l3-stheno-8b", "app_id": 12345, "streamed": true, "cancelled": false, "provider_name": "Infermatic", "latency": 1250, "moderation_latency": 50, "generation_time": 1200, "finish_reason": "stop", "tokens_prompt": 10, "tokens_completion": 25, "native_tokens_prompt": 10, "native_tokens_completion": 25, "native_tokens_completion_images": 0, "native_tokens_reasoning": 5, "native_tokens_cached": 3, "num_media_prompt": 1, "num_input_audio_prompt": 0, "num_video_prompt": 0, "num_media_completion": 0, "num_search_results": 5, "origin": "https://openrouter.ai/", "usage": 0.0015, "is_byok": false, "native_finish_reason": "stop", "external_user": "user-123", "api_type": "completions"}} default: application/json: {"error": {"code": 400, "message": "Invalid request parameters", "metadata": {"field": "temperature", "reason": "Must be between 0 and 2"}}, "user_id": "user-abc123"} 4XX: @@ -1732,4 +1762,32 @@ examples: application/json: {"error": {"code": 401, "message": "Missing Authentication header"}} "500": application/json: {"error": {"code": 500, "message": "Internal Server Error"}} + createEmbeddings: + speakeasy-default-create-embeddings: + requestBody: + application/json: {"input": "", "model": "Taurus"} + responses: + "200": + application/json: {"object": "list", "data": [], "model": "Model S"} + text/event-stream: "" + "400": + application/json: {"error": {"code": 400, "message": "Invalid request parameters"}} + "401": + application/json: {"error": {"code": 401, "message": "Missing Authentication header"}} + "402": + application/json: {"error": {"code": 402, "message": "Insufficient credits. Add more using https://openrouter.ai/credits"}} + "404": + application/json: {"error": {"code": 404, "message": "Resource not found"}} + "429": + application/json: {"error": {"code": 429, "message": "Rate limit exceeded"}} + "500": + application/json: {"error": {"code": 500, "message": "Internal Server Error"}} + "502": + application/json: {"error": {"code": 502, "message": "Provider returned error"}} + "503": + application/json: {"error": {"code": 503, "message": "Service temporarily unavailable"}} + "524": + application/json: {"error": {"code": 524, "message": "Request timed out. Please try again later."}} + "529": + application/json: {"error": {"code": 529, "message": "Provider returned error"}} examplesVersion: 1.0.2 diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index e32f31d1..0603f2e4 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -29,7 +29,7 @@ generation: generateNewTests: true skipResponseBodyAssertions: false typescript: - version: 0.1.0 + version: 0.1.1 acceptHeaderEnum: false additionalDependencies: dependencies: {} diff --git a/.speakeasy/in.openapi.yaml b/.speakeasy/in.openapi.yaml index a99ca6d8..74cd0506 100644 --- a/.speakeasy/in.openapi.yaml +++ b/.speakeasy/in.openapi.yaml @@ -624,6 +624,35 @@ components: type: input_file file_id: file-abc123 filename: document.pdf + ResponseInputAudio: + type: object + properties: + type: + type: string + enum: + - input_audio + input_audio: + type: object + properties: + data: + type: string + format: + type: string + enum: + - mp3 + - wav + required: + - data + - format + required: + - type + - input_audio + description: Audio input content item + example: + type: input_audio + input_audio: + data: SGVsbG8gV29ybGQ= + format: mp3 ToolCallStatus: type: string enum: @@ -665,12 +694,14 @@ components: - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' + - $ref: '#/components/schemas/ResponseInputAudio' discriminator: propertyName: type mapping: input_text: '#/components/schemas/ResponseInputText' input_image: '#/components/schemas/ResponseInputImage' input_file: '#/components/schemas/ResponseInputFile' + input_audio: '#/components/schemas/ResponseInputAudio' - type: string required: - role @@ -701,12 +732,14 @@ components: - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' + - $ref: '#/components/schemas/ResponseInputAudio' discriminator: propertyName: type mapping: input_text: '#/components/schemas/ResponseInputText' input_image: '#/components/schemas/ResponseInputImage' input_file: '#/components/schemas/ResponseInputFile' + input_audio: '#/components/schemas/ResponseInputAudio' required: - id - role @@ -997,16 +1030,11 @@ components: type: object nullable: true additionalProperties: - oneOf: + anyOf: + - type: string - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' - discriminator: - propertyName: type - mapping: - input_text: '#/components/schemas/ResponseInputText' - input_image: '#/components/schemas/ResponseInputImage' - input_file: '#/components/schemas/ResponseInputFile' required: - id OpenAIResponsesReasoningEffort: @@ -3260,12 +3288,14 @@ components: - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' + - $ref: '#/components/schemas/ResponseInputAudio' discriminator: propertyName: type mapping: input_text: '#/components/schemas/ResponseInputText' input_image: '#/components/schemas/ResponseInputImage' input_file: '#/components/schemas/ResponseInputFile' + input_audio: '#/components/schemas/ResponseInputAudio' - type: string required: - role @@ -3297,12 +3327,14 @@ components: - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' + - $ref: '#/components/schemas/ResponseInputAudio' discriminator: propertyName: type mapping: input_text: '#/components/schemas/ResponseInputText' input_image: '#/components/schemas/ResponseInputImage' input_file: '#/components/schemas/ResponseInputFile' + input_audio: '#/components/schemas/ResponseInputAudio' required: - role - content @@ -4584,6 +4616,10 @@ components: uptime_last_30m: 99.5 supports_implicit_caching: true __schema0: + anyOf: + - $ref: '#/components/schemas/ChatCompletionFinishReason' + - type: 'null' + ModelName: type: string ChatMessageContentItemText: type: object @@ -4767,6 +4803,14 @@ components: - completion_tokens - prompt_tokens - total_tokens + ChatCompletionFinishReason: + type: string + enum: + - tool_calls + - stop + - length + - content_filter + - error JSONSchemaConfig: type: object properties: @@ -4980,11 +5024,11 @@ components: items: $ref: '#/components/schemas/Message' model: - $ref: '#/components/schemas/__schema0' + $ref: '#/components/schemas/ModelName' models: type: array items: - $ref: '#/components/schemas/__schema0' + $ref: '#/components/schemas/ModelName' frequency_penalty: anyOf: - type: number @@ -5214,12 +5258,12 @@ components: - type: string - type: 'null' type: - type: string + anyOf: + - type: string + - type: 'null' required: - code - message - - param - - type additionalProperties: false required: - error @@ -5354,11 +5398,11 @@ components: type: object properties: model: - $ref: '#/components/schemas/__schema0' + $ref: '#/components/schemas/ModelName' models: type: array items: - $ref: '#/components/schemas/__schema0' + $ref: '#/components/schemas/ModelName' prompt: anyOf: - type: string @@ -5896,6 +5940,278 @@ paths: application/json: schema: $ref: '#/components/schemas/InternalServerResponse' + /embeddings: + post: + x-speakeasy-name-override: generate + tags: + - Embeddings + summary: Submit an embedding request + description: Submits an embedding request to the embeddings router + requestBody: + content: + application/json: + schema: + type: object + properties: + input: + anyOf: + - type: string + - type: array + items: + type: string + - type: array + items: + type: number + - type: array + items: + type: array + items: + type: number + model: + type: string + provider: + type: object + properties: + allow_fallbacks: + type: boolean + nullable: true + description: > + Whether to allow backup providers to serve requests + + - true: (default) when the primary provider (or your custom providers in "order") is + unavailable, use the next best provider. + + - false: use only the primary/custom provider, and return the upstream error if it's + unavailable. + require_parameters: + type: boolean + nullable: true + description: >- + Whether to filter providers to only those that support the parameters you've provided. If this + setting is omitted or set to false, then providers will receive only the parameters they + support, and ignore the rest. + data_collection: + type: string + nullable: true + enum: + - deny + - allow + example: deny + description: > + Data collection setting. If no available model provider meets the requirement, your request will + return an error. + + - allow: (default) allow providers which store user data non-transiently and may train on it + + - deny: use only providers which do not collect user data. + zdr: + type: boolean + nullable: true + description: >- + Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. When true, only + endpoints that do not retain prompts will be used. + example: true + order: + type: array + nullable: true + items: + anyOf: + - $ref: '#/components/schemas/ProviderName' + - type: string + description: >- + An ordered list of provider slugs. The router will attempt to use the first provider in the + subset of this list that supports your requested model, and fall back to the next if it is + unavailable. If no providers are available, the request will fail with an error message. + only: + type: array + nullable: true + items: + anyOf: + - $ref: '#/components/schemas/ProviderName' + - type: string + description: >- + List of provider slugs to allow. If provided, this list is merged with your account-wide allowed + provider settings for this request. + ignore: + type: array + nullable: true + items: + anyOf: + - $ref: '#/components/schemas/ProviderName' + - type: string + description: >- + List of provider slugs to ignore. If provided, this list is merged with your account-wide + ignored provider settings for this request. + quantizations: + type: array + nullable: true + items: + $ref: '#/components/schemas/Quantization' + description: A list of quantization levels to filter the provider by. + sort: + type: string + nullable: true + enum: + - price + - throughput + - latency + example: price + description: >- + The sorting strategy to use for this request, if "order" is not specified. When set, no load + balancing is performed. + max_price: + type: object + properties: + prompt: + $ref: '#/components/schemas/BigNumberUnion' + completion: + $ref: '#/components/schemas/BigNumberUnion' + image: + $ref: '#/components/schemas/BigNumberUnion' + audio: + $ref: '#/components/schemas/BigNumberUnion' + request: + $ref: '#/components/schemas/BigNumberUnion' + additionalProperties: false + description: >- + The object specifying the maximum price you want to pay for this request. USD price per million + tokens, for prompt and completion. + experimental: + type: object + nullable: true + properties: {} + encoding_format: + anyOf: + - type: string + enum: + - float + - type: string + enum: + - base64 + user: + type: string + required: + - input + - model + required: true + responses: + '200': + description: Embedding response + content: + application/json: + schema: + type: object + properties: + id: + type: string + object: + type: string + enum: + - list + data: + type: array + items: + type: object + properties: + object: + type: string + enum: + - embedding + embedding: + anyOf: + - type: array + items: + type: number + - type: string + index: + type: number + required: + - object + - embedding + model: + type: string + usage: + type: object + properties: + prompt_tokens: + type: number + total_tokens: + type: number + cost: + type: number + required: + - prompt_tokens + - total_tokens + required: + - object + - data + - model + text/event-stream: + schema: + type: string + description: Not used for embeddings - embeddings do not support streaming + x-speakeasy-sse-sentinel: '[DONE]' + '400': + description: Bad Request - Invalid request parameters or malformed input + content: + application/json: + schema: + $ref: '#/components/schemas/BadRequestResponse' + '401': + description: Unauthorized - Authentication required or invalid credentials + content: + application/json: + schema: + $ref: '#/components/schemas/UnauthorizedResponse' + '402': + description: Payment Required - Insufficient credits or quota to complete request + content: + application/json: + schema: + $ref: '#/components/schemas/PaymentRequiredResponse' + '404': + description: Not Found - Resource does not exist + content: + application/json: + schema: + $ref: '#/components/schemas/NotFoundResponse' + '429': + description: Too Many Requests - Rate limit exceeded + content: + application/json: + schema: + $ref: '#/components/schemas/TooManyRequestsResponse' + '500': + description: Internal Server Error - Unexpected server error + content: + application/json: + schema: + $ref: '#/components/schemas/InternalServerResponse' + '502': + description: Bad Gateway - Provider/upstream API failure + content: + application/json: + schema: + $ref: '#/components/schemas/BadGatewayResponse' + '503': + description: Service Unavailable - Service temporarily unavailable + content: + application/json: + schema: + $ref: '#/components/schemas/ServiceUnavailableResponse' + '524': + description: Cloudflare Timeout - Provider request timed out at CDN edge + content: + application/json: + schema: + $ref: '#/components/schemas/EdgeNetworkTimeoutResponse' + '529': + description: Provider Overloaded - Provider is temporarily overloaded + content: + application/json: + schema: + $ref: '#/components/schemas/ProviderOverloadedResponse' + operationId: createEmbeddings /generation: get: tags: @@ -6035,6 +6351,11 @@ paths: nullable: true description: Number of audio inputs in the prompt example: 0 + num_video_prompt: + type: number + nullable: true + description: Number of video inputs in the prompt + example: 0 num_media_completion: type: number nullable: true @@ -6099,6 +6420,7 @@ paths: - native_tokens_cached - num_media_prompt - num_input_audio_prompt + - num_video_prompt - num_media_completion - num_search_results - origin @@ -7936,6 +8258,8 @@ tags: description: Text completion endpoints - name: Credits description: Credit management endpoints + - name: Embeddings + description: Text embedding endpoints - name: Endpoints description: Endpoint information - name: Generations diff --git a/.speakeasy/out.openapi.yaml b/.speakeasy/out.openapi.yaml index 7bdcac62..c879271c 100644 --- a/.speakeasy/out.openapi.yaml +++ b/.speakeasy/out.openapi.yaml @@ -630,6 +630,36 @@ components: type: input_file file_id: file-abc123 filename: document.pdf + ResponseInputAudio: + type: object + properties: + type: + type: string + enum: + - input_audio + input_audio: + type: object + properties: + data: + type: string + format: + type: string + enum: + - mp3 + - wav + x-speakeasy-unknown-values: allow + required: + - data + - format + required: + - type + - input_audio + description: Audio input content item + example: + type: input_audio + input_audio: + data: SGVsbG8gV29ybGQ= + format: mp3 ToolCallStatus: type: string enum: @@ -672,12 +702,14 @@ components: - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' + - $ref: '#/components/schemas/ResponseInputAudio' discriminator: propertyName: type mapping: input_text: '#/components/schemas/ResponseInputText' input_image: '#/components/schemas/ResponseInputImage' input_file: '#/components/schemas/ResponseInputFile' + input_audio: '#/components/schemas/ResponseInputAudio' - type: string required: - role @@ -708,12 +740,14 @@ components: - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' + - $ref: '#/components/schemas/ResponseInputAudio' discriminator: propertyName: type mapping: input_text: '#/components/schemas/ResponseInputText' input_image: '#/components/schemas/ResponseInputImage' input_file: '#/components/schemas/ResponseInputFile' + input_audio: '#/components/schemas/ResponseInputAudio' required: - id - role @@ -1005,16 +1039,11 @@ components: type: object nullable: true additionalProperties: - oneOf: + anyOf: + - type: string - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' - discriminator: - propertyName: type - mapping: - input_text: '#/components/schemas/ResponseInputText' - input_image: '#/components/schemas/ResponseInputImage' - input_file: '#/components/schemas/ResponseInputFile' required: - id OpenAIResponsesReasoningEffort: @@ -3275,12 +3304,14 @@ components: - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' + - $ref: '#/components/schemas/ResponseInputAudio' discriminator: propertyName: type mapping: input_text: '#/components/schemas/ResponseInputText' input_image: '#/components/schemas/ResponseInputImage' input_file: '#/components/schemas/ResponseInputFile' + input_audio: '#/components/schemas/ResponseInputAudio' - type: string required: - role @@ -3312,12 +3343,14 @@ components: - $ref: '#/components/schemas/ResponseInputText' - $ref: '#/components/schemas/ResponseInputImage' - $ref: '#/components/schemas/ResponseInputFile' + - $ref: '#/components/schemas/ResponseInputAudio' discriminator: propertyName: type mapping: input_text: '#/components/schemas/ResponseInputText' input_image: '#/components/schemas/ResponseInputImage' input_file: '#/components/schemas/ResponseInputFile' + input_audio: '#/components/schemas/ResponseInputAudio' required: - role - content @@ -4608,6 +4641,8 @@ components: anyOf: - $ref: '#/components/schemas/ChatCompletionFinishReason' - type: 'null' + ModelName: + type: string ChatMessageContentItemText: type: object properties: @@ -5014,7 +5049,11 @@ components: items: $ref: '#/components/schemas/Message' model: - type: string + $ref: '#/components/schemas/ModelName' + models: + type: array + items: + $ref: '#/components/schemas/ModelName' frequency_penalty: anyOf: - type: number @@ -5150,7 +5189,6 @@ components: type: string required: - messages - - model ChatResponseChoice: type: object properties: @@ -5246,12 +5284,12 @@ components: - type: string - type: 'null' type: - type: string + anyOf: + - type: string + - type: 'null' required: - code - message - - param - - type additionalProperties: false required: - error @@ -5387,7 +5425,11 @@ components: type: object properties: model: - type: string + $ref: '#/components/schemas/ModelName' + models: + type: array + items: + $ref: '#/components/schemas/ModelName' prompt: anyOf: - type: string @@ -5531,7 +5573,6 @@ components: type: object - type: 'null' required: - - model - prompt CompletionChoice: type: object @@ -5926,6 +5967,270 @@ paths: application/json: schema: $ref: '#/components/schemas/InternalServerResponse' + /embeddings: + post: + x-speakeasy-name-override: generate + tags: + - Embeddings + summary: Submit an embedding request + description: Submits an embedding request to the embeddings router + requestBody: + content: + application/json: + schema: + type: object + properties: + input: + anyOf: + - type: string + - type: array + items: + type: string + - type: array + items: + type: number + - type: array + items: + type: array + items: + type: number + model: + type: string + provider: + type: object + properties: + allow_fallbacks: + type: boolean + nullable: true + description: > + Whether to allow backup providers to serve requests + + - true: (default) when the primary provider (or your custom providers in "order") is unavailable, use the next best provider. + + - false: use only the primary/custom provider, and return the upstream error if it's unavailable. + + require_parameters: + type: boolean + nullable: true + description: >- + Whether to filter providers to only those that support the parameters you've provided. If this setting is omitted or set to false, then providers will receive only the parameters they support, and ignore the rest. + data_collection: + type: string + nullable: true + enum: + - deny + - allow + example: deny + description: > + Data collection setting. If no available model provider meets the requirement, your request will return an error. + + - allow: (default) allow providers which store user data non-transiently and may train on it + + - deny: use only providers which do not collect user data. + + x-speakeasy-unknown-values: allow + zdr: + type: boolean + nullable: true + description: >- + Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. When true, only endpoints that do not retain prompts will be used. + example: true + order: + type: array + nullable: true + items: + anyOf: + - $ref: '#/components/schemas/ProviderName' + - type: string + description: >- + An ordered list of provider slugs. The router will attempt to use the first provider in the subset of this list that supports your requested model, and fall back to the next if it is unavailable. If no providers are available, the request will fail with an error message. + only: + type: array + nullable: true + items: + anyOf: + - $ref: '#/components/schemas/ProviderName' + - type: string + description: >- + List of provider slugs to allow. If provided, this list is merged with your account-wide allowed provider settings for this request. + ignore: + type: array + nullable: true + items: + anyOf: + - $ref: '#/components/schemas/ProviderName' + - type: string + description: >- + List of provider slugs to ignore. If provided, this list is merged with your account-wide ignored provider settings for this request. + quantizations: + type: array + nullable: true + items: + $ref: '#/components/schemas/Quantization' + description: A list of quantization levels to filter the provider by. + sort: + type: string + nullable: true + enum: + - price + - throughput + - latency + example: price + description: >- + The sorting strategy to use for this request, if "order" is not specified. When set, no load balancing is performed. + x-speakeasy-unknown-values: allow + max_price: + type: object + properties: + prompt: + $ref: '#/components/schemas/BigNumberUnion' + completion: + $ref: '#/components/schemas/BigNumberUnion' + image: + $ref: '#/components/schemas/BigNumberUnion' + audio: + $ref: '#/components/schemas/BigNumberUnion' + request: + $ref: '#/components/schemas/BigNumberUnion' + additionalProperties: false + description: >- + The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion. + experimental: + type: object + nullable: true + properties: {} + encoding_format: + anyOf: + - type: string + enum: + - float + - type: string + enum: + - base64 + user: + type: string + required: + - input + - model + required: true + responses: + '200': + description: Embedding response + content: + application/json: + schema: + type: object + properties: + id: + type: string + object: + type: string + enum: + - list + data: + type: array + items: + type: object + properties: + object: + type: string + enum: + - embedding + embedding: + anyOf: + - type: array + items: + type: number + - type: string + index: + type: number + required: + - object + - embedding + model: + type: string + usage: + type: object + properties: + prompt_tokens: + type: number + total_tokens: + type: number + cost: + type: number + required: + - prompt_tokens + - total_tokens + required: + - object + - data + - model + text/event-stream: + schema: + type: string + description: Not used for embeddings - embeddings do not support streaming + x-speakeasy-sse-sentinel: '[DONE]' + '400': + description: Bad Request - Invalid request parameters or malformed input + content: + application/json: + schema: + $ref: '#/components/schemas/BadRequestResponse' + '401': + description: Unauthorized - Authentication required or invalid credentials + content: + application/json: + schema: + $ref: '#/components/schemas/UnauthorizedResponse' + '402': + description: Payment Required - Insufficient credits or quota to complete request + content: + application/json: + schema: + $ref: '#/components/schemas/PaymentRequiredResponse' + '404': + description: Not Found - Resource does not exist + content: + application/json: + schema: + $ref: '#/components/schemas/NotFoundResponse' + '429': + description: Too Many Requests - Rate limit exceeded + content: + application/json: + schema: + $ref: '#/components/schemas/TooManyRequestsResponse' + '500': + description: Internal Server Error - Unexpected server error + content: + application/json: + schema: + $ref: '#/components/schemas/InternalServerResponse' + '502': + description: Bad Gateway - Provider/upstream API failure + content: + application/json: + schema: + $ref: '#/components/schemas/BadGatewayResponse' + '503': + description: Service Unavailable - Service temporarily unavailable + content: + application/json: + schema: + $ref: '#/components/schemas/ServiceUnavailableResponse' + '524': + description: Cloudflare Timeout - Provider request timed out at CDN edge + content: + application/json: + schema: + $ref: '#/components/schemas/EdgeNetworkTimeoutResponse' + '529': + description: Provider Overloaded - Provider is temporarily overloaded + content: + application/json: + schema: + $ref: '#/components/schemas/ProviderOverloadedResponse' + operationId: createEmbeddings /generation: get: tags: @@ -6065,6 +6370,11 @@ paths: nullable: true description: Number of audio inputs in the prompt example: 0 + num_video_prompt: + type: number + nullable: true + description: Number of video inputs in the prompt + example: 0 num_media_completion: type: number nullable: true @@ -6130,6 +6440,7 @@ paths: - native_tokens_cached - num_media_prompt - num_input_audio_prompt + - num_video_prompt - num_media_completion - num_search_results - origin @@ -7956,6 +8267,8 @@ tags: description: Text completion endpoints - name: Credits description: Credit management endpoints + - name: Embeddings + description: Text embedding endpoints - name: Endpoints description: Endpoint information - name: Generations diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 0c480ad6..471bb59c 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,20 +1,21 @@ -speakeasyVersion: 1.648.1 +speakeasyVersion: 1.649.0 sources: OpenRouter API: sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:1076c98248df2a8c6c6a22cb2fcefd3a517f2dc346c0c5b410abfe301bdb1dad - sourceBlobDigest: sha256:da053f100fc1b8b64975f7612dd8970661444f9156cd295a6cc49fd5914e8247 + sourceRevisionDigest: sha256:64795ed6576394aed3f6017e7251cbbba10dbea815eed59704d3f181636acf83 + sourceBlobDigest: sha256:8b649cac738303293760c8dc40d56c068cd3d7d3a1a02ec193701759dc723b79 tags: - latest + - staging - 1.0.0 targets: openrouter: source: OpenRouter API sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:1076c98248df2a8c6c6a22cb2fcefd3a517f2dc346c0c5b410abfe301bdb1dad - sourceBlobDigest: sha256:da053f100fc1b8b64975f7612dd8970661444f9156cd295a6cc49fd5914e8247 + sourceRevisionDigest: sha256:64795ed6576394aed3f6017e7251cbbba10dbea815eed59704d3f181636acf83 + sourceBlobDigest: sha256:8b649cac738303293760c8dc40d56c068cd3d7d3a1a02ec193701759dc723b79 codeSamplesNamespace: open-router-chat-completions-api-typescript-code-samples - codeSamplesRevisionDigest: sha256:812e850dbf1a556527446c6d855475fd5019953bfb0156058fd5e003beb83b79 + codeSamplesRevisionDigest: sha256:f99c1436bd4d779679b3220659d47b10a13ae0464ea036314547fe9bd52ceb95 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/docs/models/chaterrorerror.md b/docs/models/chaterrorerror.md index 3dbbf0ef..f0436c70 100644 --- a/docs/models/chaterrorerror.md +++ b/docs/models/chaterrorerror.md @@ -8,8 +8,6 @@ import { ChatErrorError } from "@openrouter/sdk/models"; let value: ChatErrorError = { code: "", message: "", - param: "", - type: "", }; ``` @@ -19,5 +17,5 @@ let value: ChatErrorError = { | ------------------ | ------------------ | ------------------ | ------------------ | | `code` | *models.Code* | :heavy_check_mark: | N/A | | `message` | *string* | :heavy_check_mark: | N/A | -| `param` | *string* | :heavy_check_mark: | N/A | -| `type` | *string* | :heavy_check_mark: | N/A | \ No newline at end of file +| `param` | *string* | :heavy_minus_sign: | N/A | +| `type` | *string* | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/chatgenerationparams.md b/docs/models/chatgenerationparams.md index cc3d6483..12e24b3b 100644 --- a/docs/models/chatgenerationparams.md +++ b/docs/models/chatgenerationparams.md @@ -12,7 +12,6 @@ let value: ChatGenerationParams = { content: "", }, ], - model: "Mustang", }; ``` @@ -21,7 +20,8 @@ let value: ChatGenerationParams = { | Field | Type | Required | Description | | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | | `messages` | *models.Message*[] | :heavy_check_mark: | N/A | -| `model` | *string* | :heavy_check_mark: | N/A | +| `model` | *string* | :heavy_minus_sign: | N/A | +| `models` | *string*[] | :heavy_minus_sign: | N/A | | `frequencyPenalty` | *number* | :heavy_minus_sign: | N/A | | `logitBias` | Record | :heavy_minus_sign: | N/A | | `logprobs` | *boolean* | :heavy_minus_sign: | N/A | diff --git a/docs/models/chatmessagecontentitemaudio.md b/docs/models/chatmessagecontentitemaudio.md index 4971aa58..bb25a18e 100644 --- a/docs/models/chatmessagecontentitemaudio.md +++ b/docs/models/chatmessagecontentitemaudio.md @@ -16,7 +16,7 @@ let value: ChatMessageContentItemAudio = { ## Fields -| Field | Type | Required | Description | -| -------------------------------------------- | -------------------------------------------- | -------------------------------------------- | -------------------------------------------- | -| `type` | *string* | :heavy_check_mark: | N/A | -| `inputAudio` | [models.InputAudio](../models/inputaudio.md) | :heavy_check_mark: | N/A | \ No newline at end of file +| Field | Type | Required | Description | +| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | +| `type` | *string* | :heavy_check_mark: | N/A | +| `inputAudio` | [models.ChatMessageContentItemAudioInputAudio](../models/chatmessagecontentitemaudioinputaudio.md) | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/models/inputaudio.md b/docs/models/chatmessagecontentitemaudioinputaudio.md similarity index 89% rename from docs/models/inputaudio.md rename to docs/models/chatmessagecontentitemaudioinputaudio.md index d97395fd..f18856c0 100644 --- a/docs/models/inputaudio.md +++ b/docs/models/chatmessagecontentitemaudioinputaudio.md @@ -1,13 +1,13 @@ -# InputAudio +# ChatMessageContentItemAudioInputAudio ## Example Usage ```typescript -import { InputAudio } from "@openrouter/sdk/models"; +import { ChatMessageContentItemAudioInputAudio } from "@openrouter/sdk/models"; -let value: InputAudio = { +let value: ChatMessageContentItemAudioInputAudio = { data: "", - format: "mp3", + format: "wav", }; ``` diff --git a/docs/models/completioncreateparams.md b/docs/models/completioncreateparams.md index a4da2a46..e0cc9880 100644 --- a/docs/models/completioncreateparams.md +++ b/docs/models/completioncreateparams.md @@ -6,8 +6,7 @@ import { CompletionCreateParams } from "@openrouter/sdk/models"; let value: CompletionCreateParams = { - model: "Model Y", - prompt: "", + prompt: [], }; ``` @@ -15,7 +14,8 @@ let value: CompletionCreateParams = { | Field | Type | Required | Description | | -------------------------------------------------- | -------------------------------------------------- | -------------------------------------------------- | -------------------------------------------------- | -| `model` | *string* | :heavy_check_mark: | N/A | +| `model` | *string* | :heavy_minus_sign: | N/A | +| `models` | *string*[] | :heavy_minus_sign: | N/A | | `prompt` | *models.Prompt* | :heavy_check_mark: | N/A | | `bestOf` | *number* | :heavy_minus_sign: | N/A | | `echo` | *boolean* | :heavy_minus_sign: | N/A | diff --git a/docs/models/openairesponsesinputcontent1.md b/docs/models/openairesponsesinputcontent1.md index f638b252..4e57c5fa 100644 --- a/docs/models/openairesponsesinputcontent1.md +++ b/docs/models/openairesponsesinputcontent1.md @@ -29,3 +29,15 @@ const value: models.ResponseInputFile = { }; ``` +### `models.ResponseInputAudio` + +```typescript +const value: models.ResponseInputAudio = { + type: "input_audio", + inputAudio: { + data: "SGVsbG8gV29ybGQ=", + format: "mp3", + }, +}; +``` + diff --git a/docs/models/openairesponsesinputcontent3.md b/docs/models/openairesponsesinputcontent3.md index 6c3392e7..df1197c5 100644 --- a/docs/models/openairesponsesinputcontent3.md +++ b/docs/models/openairesponsesinputcontent3.md @@ -29,3 +29,15 @@ const value: models.ResponseInputFile = { }; ``` +### `models.ResponseInputAudio` + +```typescript +const value: models.ResponseInputAudio = { + type: "input_audio", + inputAudio: { + data: "SGVsbG8gV29ybGQ=", + format: "mp3", + }, +}; +``` + diff --git a/docs/models/openresponseseasyinputmessagecontent1.md b/docs/models/openresponseseasyinputmessagecontent1.md index 19dd0807..97371515 100644 --- a/docs/models/openresponseseasyinputmessagecontent1.md +++ b/docs/models/openresponseseasyinputmessagecontent1.md @@ -29,3 +29,15 @@ const value: models.ResponseInputFile = { }; ``` +### `models.ResponseInputAudio` + +```typescript +const value: models.ResponseInputAudio = { + type: "input_audio", + inputAudio: { + data: "SGVsbG8gV29ybGQ=", + format: "mp3", + }, +}; +``` + diff --git a/docs/models/openresponsesinputmessageitemcontent.md b/docs/models/openresponsesinputmessageitemcontent.md index ac5c8fe9..b28e0fcc 100644 --- a/docs/models/openresponsesinputmessageitemcontent.md +++ b/docs/models/openresponsesinputmessageitemcontent.md @@ -29,3 +29,15 @@ const value: models.ResponseInputFile = { }; ``` +### `models.ResponseInputAudio` + +```typescript +const value: models.ResponseInputAudio = { + type: "input_audio", + inputAudio: { + data: "SGVsbG8gV29ybGQ=", + format: "mp3", + }, +}; +``` + diff --git a/docs/models/operations/createembeddingsdata.md b/docs/models/operations/createembeddingsdata.md new file mode 100644 index 00000000..b6acb226 --- /dev/null +++ b/docs/models/operations/createembeddingsdata.md @@ -0,0 +1,20 @@ +# CreateEmbeddingsData + +## Example Usage + +```typescript +import { CreateEmbeddingsData } from "@openrouter/sdk/models/operations"; + +let value: CreateEmbeddingsData = { + object: "embedding", + embedding: "", +}; +``` + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | +| `object` | [operations.ObjectEmbedding](../../models/operations/objectembedding.md) | :heavy_check_mark: | N/A | +| `embedding` | *operations.Embedding* | :heavy_check_mark: | N/A | +| `index` | *number* | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/createembeddingsprovider.md b/docs/models/operations/createembeddingsprovider.md new file mode 100644 index 00000000..5e33a470 --- /dev/null +++ b/docs/models/operations/createembeddingsprovider.md @@ -0,0 +1,25 @@ +# CreateEmbeddingsProvider + +## Example Usage + +```typescript +import { CreateEmbeddingsProvider } from "@openrouter/sdk/models/operations"; + +let value: CreateEmbeddingsProvider = {}; +``` + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `allowFallbacks` | *boolean* | :heavy_minus_sign: | Whether to allow backup providers to serve requests
- true: (default) when the primary provider (or your custom providers in "order") is unavailable, use the next best provider.
- false: use only the primary/custom provider, and return the upstream error if it's unavailable.
| | +| `requireParameters` | *boolean* | :heavy_minus_sign: | Whether to filter providers to only those that support the parameters you've provided. If this setting is omitted or set to false, then providers will receive only the parameters they support, and ignore the rest. | | +| `dataCollection` | [operations.DataCollection](../../models/operations/datacollection.md) | :heavy_minus_sign: | Data collection setting. If no available model provider meets the requirement, your request will return an error.
- allow: (default) allow providers which store user data non-transiently and may train on it
- deny: use only providers which do not collect user data.
| deny | +| `zdr` | *boolean* | :heavy_minus_sign: | Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. When true, only endpoints that do not retain prompts will be used. | true | +| `order` | *operations.Order*[] | :heavy_minus_sign: | An ordered list of provider slugs. The router will attempt to use the first provider in the subset of this list that supports your requested model, and fall back to the next if it is unavailable. If no providers are available, the request will fail with an error message. | | +| `only` | *operations.Only*[] | :heavy_minus_sign: | List of provider slugs to allow. If provided, this list is merged with your account-wide allowed provider settings for this request. | | +| `ignore` | *operations.Ignore*[] | :heavy_minus_sign: | List of provider slugs to ignore. If provided, this list is merged with your account-wide ignored provider settings for this request. | | +| `quantizations` | [models.Quantization](../../models/quantization.md)[] | :heavy_minus_sign: | A list of quantization levels to filter the provider by. | | +| `sort` | [operations.Sort](../../models/operations/sort.md) | :heavy_minus_sign: | The sorting strategy to use for this request, if "order" is not specified. When set, no load balancing is performed. | price | +| `maxPrice` | [operations.MaxPrice](../../models/operations/maxprice.md) | :heavy_minus_sign: | The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion. | | +| `experimental` | [operations.Experimental](../../models/operations/experimental.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file diff --git a/docs/models/operations/createembeddingsrequest.md b/docs/models/operations/createembeddingsrequest.md new file mode 100644 index 00000000..12705ca4 --- /dev/null +++ b/docs/models/operations/createembeddingsrequest.md @@ -0,0 +1,26 @@ +# CreateEmbeddingsRequest + +## Example Usage + +```typescript +import { CreateEmbeddingsRequest } from "@openrouter/sdk/models/operations"; + +let value: CreateEmbeddingsRequest = { + input: [ + 669.24, + 4968.43, + 3849.69, + ], + model: "Altima", +}; +``` + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | +| `input` | *operations.Input* | :heavy_check_mark: | N/A | +| `model` | *string* | :heavy_check_mark: | N/A | +| `provider` | [operations.CreateEmbeddingsProvider](../../models/operations/createembeddingsprovider.md) | :heavy_minus_sign: | N/A | +| `encodingFormat` | *operations.EncodingFormat* | :heavy_minus_sign: | N/A | +| `user` | *string* | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/createembeddingsresponse.md b/docs/models/operations/createembeddingsresponse.md new file mode 100644 index 00000000..cfc7f402 --- /dev/null +++ b/docs/models/operations/createembeddingsresponse.md @@ -0,0 +1,21 @@ +# CreateEmbeddingsResponse + + +## Supported Types + +### `operations.CreateEmbeddingsResponseBody` + +```typescript +const value: operations.CreateEmbeddingsResponseBody = { + object: "list", + data: [], + model: "Focus", +}; +``` + +### `string` + +```typescript +const value: string = ""; +``` + diff --git a/docs/models/operations/createembeddingsresponsebody.md b/docs/models/operations/createembeddingsresponsebody.md new file mode 100644 index 00000000..18423c1d --- /dev/null +++ b/docs/models/operations/createembeddingsresponsebody.md @@ -0,0 +1,25 @@ +# CreateEmbeddingsResponseBody + +Embedding response + +## Example Usage + +```typescript +import { CreateEmbeddingsResponseBody } from "@openrouter/sdk/models/operations"; + +let value: CreateEmbeddingsResponseBody = { + object: "list", + data: [], + model: "Focus", +}; +``` + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | +| `id` | *string* | :heavy_minus_sign: | N/A | +| `object` | [operations.ObjectT](../../models/operations/objectt.md) | :heavy_check_mark: | N/A | +| `data` | [operations.CreateEmbeddingsData](../../models/operations/createembeddingsdata.md)[] | :heavy_check_mark: | N/A | +| `model` | *string* | :heavy_check_mark: | N/A | +| `usage` | [operations.Usage](../../models/operations/usage.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/datacollection.md b/docs/models/operations/datacollection.md new file mode 100644 index 00000000..d832689f --- /dev/null +++ b/docs/models/operations/datacollection.md @@ -0,0 +1,22 @@ +# DataCollection + +Data collection setting. If no available model provider meets the requirement, your request will return an error. +- allow: (default) allow providers which store user data non-transiently and may train on it +- deny: use only providers which do not collect user data. + + +## Example Usage + +```typescript +import { DataCollection } from "@openrouter/sdk/models/operations"; + +let value: DataCollection = "deny"; +``` + +## Values + +This is an open enum. Unrecognized values will be captured as the `Unrecognized` branded type. + +```typescript +"deny" | "allow" | Unrecognized +``` \ No newline at end of file diff --git a/docs/models/operations/embedding.md b/docs/models/operations/embedding.md new file mode 100644 index 00000000..840767b6 --- /dev/null +++ b/docs/models/operations/embedding.md @@ -0,0 +1,21 @@ +# Embedding + + +## Supported Types + +### `number[]` + +```typescript +const value: number[] = [ + 3390.48, + 1336.21, + 9437.99, +]; +``` + +### `string` + +```typescript +const value: string = ""; +``` + diff --git a/docs/models/operations/encodingformat.md b/docs/models/operations/encodingformat.md new file mode 100644 index 00000000..7b5f69a7 --- /dev/null +++ b/docs/models/operations/encodingformat.md @@ -0,0 +1,17 @@ +# EncodingFormat + + +## Supported Types + +### `operations.EncodingFormatFloat` + +```typescript +const value: operations.EncodingFormatFloat = "float"; +``` + +### `operations.EncodingFormatBase64` + +```typescript +const value: operations.EncodingFormatBase64 = "base64"; +``` + diff --git a/docs/models/operations/encodingformatbase64.md b/docs/models/operations/encodingformatbase64.md new file mode 100644 index 00000000..91c09f3a --- /dev/null +++ b/docs/models/operations/encodingformatbase64.md @@ -0,0 +1,15 @@ +# EncodingFormatBase64 + +## Example Usage + +```typescript +import { EncodingFormatBase64 } from "@openrouter/sdk/models/operations"; + +let value: EncodingFormatBase64 = "base64"; +``` + +## Values + +```typescript +"base64" +``` \ No newline at end of file diff --git a/docs/models/operations/encodingformatfloat.md b/docs/models/operations/encodingformatfloat.md new file mode 100644 index 00000000..018279dd --- /dev/null +++ b/docs/models/operations/encodingformatfloat.md @@ -0,0 +1,15 @@ +# EncodingFormatFloat + +## Example Usage + +```typescript +import { EncodingFormatFloat } from "@openrouter/sdk/models/operations"; + +let value: EncodingFormatFloat = "float"; +``` + +## Values + +```typescript +"float" +``` \ No newline at end of file diff --git a/docs/models/operations/experimental.md b/docs/models/operations/experimental.md new file mode 100644 index 00000000..b19b0ac5 --- /dev/null +++ b/docs/models/operations/experimental.md @@ -0,0 +1,14 @@ +# Experimental + +## Example Usage + +```typescript +import { Experimental } from "@openrouter/sdk/models/operations"; + +let value: Experimental = {}; +``` + +## Fields + +| Field | Type | Required | Description | +| ----------- | ----------- | ----------- | ----------- | \ No newline at end of file diff --git a/docs/models/operations/getgenerationdata.md b/docs/models/operations/getgenerationdata.md index 83bd5d01..7b452b23 100644 --- a/docs/models/operations/getgenerationdata.md +++ b/docs/models/operations/getgenerationdata.md @@ -32,6 +32,7 @@ let value: GetGenerationData = { nativeTokensCached: 3, numMediaPrompt: 1, numInputAudioPrompt: 0, + numVideoPrompt: 0, numMediaCompletion: 0, numSearchResults: 5, origin: "https://openrouter.ai/", @@ -71,6 +72,7 @@ let value: GetGenerationData = { | `nativeTokensCached` | *number* | :heavy_check_mark: | Native cached tokens as reported by provider | 3 | | `numMediaPrompt` | *number* | :heavy_check_mark: | Number of media items in the prompt | 1 | | `numInputAudioPrompt` | *number* | :heavy_check_mark: | Number of audio inputs in the prompt | 0 | +| `numVideoPrompt` | *number* | :heavy_check_mark: | Number of video inputs in the prompt | 0 | | `numMediaCompletion` | *number* | :heavy_check_mark: | Number of media items in the completion | 0 | | `numSearchResults` | *number* | :heavy_check_mark: | Number of search results included | 5 | | `origin` | *string* | :heavy_check_mark: | Origin URL of the request | https://openrouter.ai/ | diff --git a/docs/models/operations/getgenerationresponse.md b/docs/models/operations/getgenerationresponse.md index 5a382037..d91e310f 100644 --- a/docs/models/operations/getgenerationresponse.md +++ b/docs/models/operations/getgenerationresponse.md @@ -33,6 +33,7 @@ let value: GetGenerationResponse = { nativeTokensCached: 3, numMediaPrompt: 1, numInputAudioPrompt: 0, + numVideoPrompt: 0, numMediaCompletion: 0, numSearchResults: 5, origin: "https://openrouter.ai/", diff --git a/docs/models/operations/provider.md b/docs/models/operations/getparametersprovider.md similarity index 87% rename from docs/models/operations/provider.md rename to docs/models/operations/getparametersprovider.md index 0e612639..b2d88d5a 100644 --- a/docs/models/operations/provider.md +++ b/docs/models/operations/getparametersprovider.md @@ -1,11 +1,11 @@ -# Provider +# GetParametersProvider ## Example Usage ```typescript -import { Provider } from "@openrouter/sdk/models/operations"; +import { GetParametersProvider } from "@openrouter/sdk/models/operations"; -let value: Provider = "Cirrascale"; +let value: GetParametersProvider = "Hyperbolic"; ``` ## Values diff --git a/docs/models/operations/getparametersrequest.md b/docs/models/operations/getparametersrequest.md index 0e51936b..3f2605e7 100644 --- a/docs/models/operations/getparametersrequest.md +++ b/docs/models/operations/getparametersrequest.md @@ -13,8 +13,8 @@ let value: GetParametersRequest = { ## Fields -| Field | Type | Required | Description | -| ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | -| `author` | *string* | :heavy_check_mark: | N/A | -| `slug` | *string* | :heavy_check_mark: | N/A | -| `provider` | [operations.Provider](../../models/operations/provider.md) | :heavy_minus_sign: | N/A | \ No newline at end of file +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | +| `author` | *string* | :heavy_check_mark: | N/A | +| `slug` | *string* | :heavy_check_mark: | N/A | +| `provider` | [operations.GetParametersProvider](../../models/operations/getparametersprovider.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/ignore.md b/docs/models/operations/ignore.md new file mode 100644 index 00000000..de9c31d0 --- /dev/null +++ b/docs/models/operations/ignore.md @@ -0,0 +1,17 @@ +# Ignore + + +## Supported Types + +### `models.ProviderName` + +```typescript +const value: models.ProviderName = "OpenAI"; +``` + +### `string` + +```typescript +const value: string = ""; +``` + diff --git a/docs/models/operations/input.md b/docs/models/operations/input.md new file mode 100644 index 00000000..56643938 --- /dev/null +++ b/docs/models/operations/input.md @@ -0,0 +1,47 @@ +# Input + + +## Supported Types + +### `string` + +```typescript +const value: string = ""; +``` + +### `string[]` + +```typescript +const value: string[] = [ + "", + "", +]; +``` + +### `number[]` + +```typescript +const value: number[] = [ + 3390.48, + 1336.21, + 9437.99, +]; +``` + +### `number[][]` + +```typescript +const value: number[][] = [ + [ + 6206.15, + ], + [ + 8419.72, + 5863.71, + ], + [ + 2540.22, + ], +]; +``` + diff --git a/docs/models/operations/maxprice.md b/docs/models/operations/maxprice.md new file mode 100644 index 00000000..d54dfb5c --- /dev/null +++ b/docs/models/operations/maxprice.md @@ -0,0 +1,21 @@ +# MaxPrice + +The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion. + +## Example Usage + +```typescript +import { MaxPrice } from "@openrouter/sdk/models/operations"; + +let value: MaxPrice = {}; +``` + +## Fields + +| Field | Type | Required | Description | +| --------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------- | +| `prompt` | *any* | :heavy_minus_sign: | A value in string or number format that is a large number | +| `completion` | *any* | :heavy_minus_sign: | A value in string or number format that is a large number | +| `image` | *any* | :heavy_minus_sign: | A value in string or number format that is a large number | +| `audio` | *any* | :heavy_minus_sign: | A value in string or number format that is a large number | +| `request` | *any* | :heavy_minus_sign: | A value in string or number format that is a large number | \ No newline at end of file diff --git a/docs/models/operations/objectembedding.md b/docs/models/operations/objectembedding.md new file mode 100644 index 00000000..fc8fb22f --- /dev/null +++ b/docs/models/operations/objectembedding.md @@ -0,0 +1,15 @@ +# ObjectEmbedding + +## Example Usage + +```typescript +import { ObjectEmbedding } from "@openrouter/sdk/models/operations"; + +let value: ObjectEmbedding = "embedding"; +``` + +## Values + +```typescript +"embedding" +``` \ No newline at end of file diff --git a/docs/models/operations/objectt.md b/docs/models/operations/objectt.md new file mode 100644 index 00000000..6319d7be --- /dev/null +++ b/docs/models/operations/objectt.md @@ -0,0 +1,15 @@ +# ObjectT + +## Example Usage + +```typescript +import { ObjectT } from "@openrouter/sdk/models/operations"; + +let value: ObjectT = "list"; +``` + +## Values + +```typescript +"list" +``` \ No newline at end of file diff --git a/docs/models/operations/only.md b/docs/models/operations/only.md new file mode 100644 index 00000000..c4202205 --- /dev/null +++ b/docs/models/operations/only.md @@ -0,0 +1,17 @@ +# Only + + +## Supported Types + +### `models.ProviderName` + +```typescript +const value: models.ProviderName = "OpenAI"; +``` + +### `string` + +```typescript +const value: string = ""; +``` + diff --git a/docs/models/operations/order.md b/docs/models/operations/order.md new file mode 100644 index 00000000..8a2f0898 --- /dev/null +++ b/docs/models/operations/order.md @@ -0,0 +1,17 @@ +# Order + + +## Supported Types + +### `models.ProviderName` + +```typescript +const value: models.ProviderName = "OpenAI"; +``` + +### `string` + +```typescript +const value: string = ""; +``` + diff --git a/docs/models/operations/sort.md b/docs/models/operations/sort.md new file mode 100644 index 00000000..46237bad --- /dev/null +++ b/docs/models/operations/sort.md @@ -0,0 +1,19 @@ +# Sort + +The sorting strategy to use for this request, if "order" is not specified. When set, no load balancing is performed. + +## Example Usage + +```typescript +import { Sort } from "@openrouter/sdk/models/operations"; + +let value: Sort = "price"; +``` + +## Values + +This is an open enum. Unrecognized values will be captured as the `Unrecognized` branded type. + +```typescript +"price" | "throughput" | "latency" | Unrecognized +``` \ No newline at end of file diff --git a/docs/models/operations/usage.md b/docs/models/operations/usage.md new file mode 100644 index 00000000..9fd02485 --- /dev/null +++ b/docs/models/operations/usage.md @@ -0,0 +1,20 @@ +# Usage + +## Example Usage + +```typescript +import { Usage } from "@openrouter/sdk/models/operations"; + +let value: Usage = { + promptTokens: 9797.96, + totalTokens: 7874.4, +}; +``` + +## Fields + +| Field | Type | Required | Description | +| ------------------ | ------------------ | ------------------ | ------------------ | +| `promptTokens` | *number* | :heavy_check_mark: | N/A | +| `totalTokens` | *number* | :heavy_check_mark: | N/A | +| `cost` | *number* | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/responseinputaudio.md b/docs/models/responseinputaudio.md new file mode 100644 index 00000000..cad24bad --- /dev/null +++ b/docs/models/responseinputaudio.md @@ -0,0 +1,24 @@ +# ResponseInputAudio + +Audio input content item + +## Example Usage + +```typescript +import { ResponseInputAudio } from "@openrouter/sdk/models"; + +let value: ResponseInputAudio = { + type: "input_audio", + inputAudio: { + data: "SGVsbG8gV29ybGQ=", + format: "mp3", + }, +}; +``` + +## Fields + +| Field | Type | Required | Description | +| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | +| `type` | [models.ResponseInputAudioType](../models/responseinputaudiotype.md) | :heavy_check_mark: | N/A | +| `inputAudio` | [models.ResponseInputAudioInputAudio](../models/responseinputaudioinputaudio.md) | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/models/responseinputaudioformat.md b/docs/models/responseinputaudioformat.md new file mode 100644 index 00000000..40ec3b70 --- /dev/null +++ b/docs/models/responseinputaudioformat.md @@ -0,0 +1,17 @@ +# ResponseInputAudioFormat + +## Example Usage + +```typescript +import { ResponseInputAudioFormat } from "@openrouter/sdk/models"; + +let value: ResponseInputAudioFormat = "mp3"; +``` + +## Values + +This is an open enum. Unrecognized values will be captured as the `Unrecognized` branded type. + +```typescript +"mp3" | "wav" | Unrecognized +``` \ No newline at end of file diff --git a/docs/models/responseinputaudioinputaudio.md b/docs/models/responseinputaudioinputaudio.md new file mode 100644 index 00000000..3abf5b6d --- /dev/null +++ b/docs/models/responseinputaudioinputaudio.md @@ -0,0 +1,19 @@ +# ResponseInputAudioInputAudio + +## Example Usage + +```typescript +import { ResponseInputAudioInputAudio } from "@openrouter/sdk/models"; + +let value: ResponseInputAudioInputAudio = { + data: "", + format: "wav", +}; +``` + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | +| `data` | *string* | :heavy_check_mark: | N/A | +| `format` | [models.ResponseInputAudioFormat](../models/responseinputaudioformat.md) | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/models/responseinputaudiotype.md b/docs/models/responseinputaudiotype.md new file mode 100644 index 00000000..cb04089f --- /dev/null +++ b/docs/models/responseinputaudiotype.md @@ -0,0 +1,15 @@ +# ResponseInputAudioType + +## Example Usage + +```typescript +import { ResponseInputAudioType } from "@openrouter/sdk/models"; + +let value: ResponseInputAudioType = "input_audio"; +``` + +## Values + +```typescript +"input_audio" +``` \ No newline at end of file diff --git a/docs/models/variables.md b/docs/models/variables.md index 743a9cbb..263e9f12 100644 --- a/docs/models/variables.md +++ b/docs/models/variables.md @@ -3,6 +3,12 @@ ## Supported Types +### `string` + +```typescript +const value: string = ""; +``` + ### `models.ResponseInputText` ```typescript diff --git a/docs/sdks/chat/README.md b/docs/sdks/chat/README.md index 8224c3ad..7a14c18d 100644 --- a/docs/sdks/chat/README.md +++ b/docs/sdks/chat/README.md @@ -24,7 +24,6 @@ const openRouter = new OpenRouter({ async function run() { const result = await openRouter.chat.send({ messages: [], - model: "Charger", }); console.log(result); @@ -50,7 +49,6 @@ const openRouter = new OpenRouterCore({ async function run() { const res = await chatSend(openRouter, { messages: [], - model: "Charger", }); if (res.ok) { const { value: result } = res; diff --git a/docs/sdks/completions/README.md b/docs/sdks/completions/README.md index 0e5898d5..c90ef4a8 100644 --- a/docs/sdks/completions/README.md +++ b/docs/sdks/completions/README.md @@ -23,7 +23,6 @@ const openRouter = new OpenRouter({ async function run() { const result = await openRouter.completions.generate({ - model: "Model T", prompt: "", }); @@ -49,7 +48,6 @@ const openRouter = new OpenRouterCore({ async function run() { const res = await completionsGenerate(openRouter, { - model: "Model T", prompt: "", }); if (res.ok) { diff --git a/docs/sdks/embeddings/README.md b/docs/sdks/embeddings/README.md new file mode 100644 index 00000000..d91eab20 --- /dev/null +++ b/docs/sdks/embeddings/README.md @@ -0,0 +1,112 @@ +# Embeddings +(*embeddings*) + +## Overview + +Text embedding endpoints + +### Available Operations + +* [generate](#generate) - Submit an embedding request + +## generate + +Submits an embedding request to the embeddings router + +### Example Usage + + +```typescript +import { OpenRouter } from "@openrouter/sdk"; + +const openRouter = new OpenRouter({ + apiKey: process.env["OPENROUTER_API_KEY"] ?? "", +}); + +async function run() { + const result = await openRouter.embeddings.generate({ + input: "", + model: "Taurus", + }); + + console.log(result); +} + +run(); +``` + +### Standalone function + +The standalone function version of this method: + +```typescript +import { OpenRouterCore } from "@openrouter/sdk/core.js"; +import { embeddingsGenerate } from "@openrouter/sdk/funcs/embeddingsGenerate.js"; + +// Use `OpenRouterCore` for best tree-shaking performance. +// You can create one instance of it to use across an application. +const openRouter = new OpenRouterCore({ + apiKey: process.env["OPENROUTER_API_KEY"] ?? "", +}); + +async function run() { + const res = await embeddingsGenerate(openRouter, { + input: "", + model: "Taurus", + }); + if (res.ok) { + const { value: result } = res; + console.log(result); + } else { + console.log("embeddingsGenerate failed:", res.error); + } +} + +run(); +``` + +### React hooks and utilities + +This method can be used in React components through the following hooks and +associated utilities. + +> Check out [this guide][hook-guide] for information about each of the utilities +> below and how to get started using React hooks. + +[hook-guide]: ../../../REACT_QUERY.md + +```tsx +import { + // Mutation hook for triggering the API call. + useEmbeddingsGenerateMutation +} from "@openrouter/sdk/react-query/embeddingsGenerate.js"; +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `request` | [operations.CreateEmbeddingsRequest](../../models/operations/createembeddingsrequest.md) | :heavy_check_mark: | The request object to use for the request. | +| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | +| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | +| `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | + +### Response + +**Promise\<[operations.CreateEmbeddingsResponse](../../models/operations/createembeddingsresponse.md)\>** + +### Errors + +| Error Type | Status Code | Content Type | +| -------------------------------------- | -------------------------------------- | -------------------------------------- | +| errors.BadRequestResponseError | 400 | application/json | +| errors.UnauthorizedResponseError | 401 | application/json | +| errors.PaymentRequiredResponseError | 402 | application/json | +| errors.NotFoundResponseError | 404 | application/json | +| errors.TooManyRequestsResponseError | 429 | application/json | +| errors.InternalServerResponseError | 500 | application/json | +| errors.BadGatewayResponseError | 502 | application/json | +| errors.ServiceUnavailableResponseError | 503 | application/json | +| errors.EdgeNetworkTimeoutResponseError | 524 | application/json | +| errors.ProviderOverloadedResponseError | 529 | application/json | +| errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/examples/nextjs-example/package-lock.json b/examples/nextjs-example/package-lock.json index 965d6db3..99b6b50f 100644 --- a/examples/nextjs-example/package-lock.json +++ b/examples/nextjs-example/package-lock.json @@ -36,7 +36,7 @@ }, "../..": { "name": "@openrouter/sdk", - "version": "0.0.1-beta.18", + "version": "0.1.1", "dependencies": { "zod": "^3.25.0 || ^4.0.0" }, diff --git a/jsr.json b/jsr.json index ae1951ec..cd61668d 100644 --- a/jsr.json +++ b/jsr.json @@ -2,7 +2,7 @@ { "name": "@openrouter/sdk", - "version": "0.1.0", + "version": "0.1.1", "exports": { ".": "./src/index.ts", "./models/errors": "./src/models/errors/index.ts", diff --git a/package-lock.json b/package-lock.json index b2a6fc3c..1e1b28f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@openrouter/sdk", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@openrouter/sdk", - "version": "0.1.0", + "version": "0.1.1", "dependencies": { "zod": "^3.25.0 || ^4.0.0" }, diff --git a/package.json b/package.json index 80c8c535..73cd28fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openrouter/sdk", - "version": "0.1.0", + "version": "0.1.1", "author": "OpenRouter", "type": "module", "main": "./esm/index.js", diff --git a/src/funcs/embeddingsGenerate.ts b/src/funcs/embeddingsGenerate.ts new file mode 100644 index 00000000..998f5969 --- /dev/null +++ b/src/funcs/embeddingsGenerate.ts @@ -0,0 +1,221 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { OpenRouterCore } from "../core.js"; +import { encodeJSON } from "../lib/encodings.js"; +import * as M from "../lib/matchers.js"; +import { compactMap } from "../lib/primitives.js"; +import { safeParse } from "../lib/schemas.js"; +import { RequestOptions } from "../lib/sdks.js"; +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; +import { pathToFunc } from "../lib/url.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../models/errors/httpclienterrors.js"; +import * as errors from "../models/errors/index.js"; +import { OpenRouterError } from "../models/errors/openroutererror.js"; +import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; +import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; +import * as operations from "../models/operations/index.js"; +import { APICall, APIPromise } from "../types/async.js"; +import { Result } from "../types/fp.js"; + +/** + * Submit an embedding request + * + * @remarks + * Submits an embedding request to the embeddings router + */ +export function embeddingsGenerate( + client: OpenRouterCore, + request: operations.CreateEmbeddingsRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.CreateEmbeddingsResponse, + | errors.BadRequestResponseError + | errors.UnauthorizedResponseError + | errors.PaymentRequiredResponseError + | errors.NotFoundResponseError + | errors.TooManyRequestsResponseError + | errors.InternalServerResponseError + | errors.BadGatewayResponseError + | errors.ServiceUnavailableResponseError + | errors.EdgeNetworkTimeoutResponseError + | errors.ProviderOverloadedResponseError + | OpenRouterError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: OpenRouterCore, + request: operations.CreateEmbeddingsRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.CreateEmbeddingsResponse, + | errors.BadRequestResponseError + | errors.UnauthorizedResponseError + | errors.PaymentRequiredResponseError + | errors.NotFoundResponseError + | errors.TooManyRequestsResponseError + | errors.InternalServerResponseError + | errors.BadGatewayResponseError + | errors.ServiceUnavailableResponseError + | errors.EdgeNetworkTimeoutResponseError + | errors.ProviderOverloadedResponseError + | OpenRouterError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.CreateEmbeddingsRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = encodeJSON("body", payload, { explode: true }); + + const path = pathToFunc("/embeddings")(); + + const headers = new Headers(compactMap({ + "Content-Type": "application/json", + Accept: "application/json;q=1, text/event-stream;q=0", + })); + + const secConfig = await extractSecurity(client._options.apiKey); + const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "createEmbeddings", + oAuth2Scopes: null, + + resolvedSecurity: requestSecurity, + + securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "POST", + baseURL: options?.serverURL, + path: path, + headers: headers, + body: body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: [ + "400", + "401", + "402", + "404", + "429", + "4XX", + "500", + "502", + "503", + "524", + "529", + "5XX", + ], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.CreateEmbeddingsResponse, + | errors.BadRequestResponseError + | errors.UnauthorizedResponseError + | errors.PaymentRequiredResponseError + | errors.NotFoundResponseError + | errors.TooManyRequestsResponseError + | errors.InternalServerResponseError + | errors.BadGatewayResponseError + | errors.ServiceUnavailableResponseError + | errors.EdgeNetworkTimeoutResponseError + | errors.ProviderOverloadedResponseError + | OpenRouterError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.CreateEmbeddingsResponse$inboundSchema), + M.text(200, operations.CreateEmbeddingsResponse$inboundSchema, { + ctype: "text/event-stream", + }), + M.jsonErr(400, errors.BadRequestResponseError$inboundSchema), + M.jsonErr(401, errors.UnauthorizedResponseError$inboundSchema), + M.jsonErr(402, errors.PaymentRequiredResponseError$inboundSchema), + M.jsonErr(404, errors.NotFoundResponseError$inboundSchema), + M.jsonErr(429, errors.TooManyRequestsResponseError$inboundSchema), + M.jsonErr(500, errors.InternalServerResponseError$inboundSchema), + M.jsonErr(502, errors.BadGatewayResponseError$inboundSchema), + M.jsonErr(503, errors.ServiceUnavailableResponseError$inboundSchema), + M.jsonErr(524, errors.EdgeNetworkTimeoutResponseError$inboundSchema), + M.jsonErr(529, errors.ProviderOverloadedResponseError$inboundSchema), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [result, { status: "complete", request: req, response }]; +} diff --git a/src/lib/config.ts b/src/lib/config.ts index 77f4411d..7df9a845 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -59,7 +59,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", openapiDocVersion: "1.0.0", - sdkVersion: "0.1.0", + sdkVersion: "0.1.1", genVersion: "2.739.1", - userAgent: "speakeasy-sdk/typescript 0.1.0 2.739.1 1.0.0 @openrouter/sdk", + userAgent: "speakeasy-sdk/typescript 0.1.1 2.739.1 1.0.0 @openrouter/sdk", } as const; diff --git a/src/models/chaterror.ts b/src/models/chaterror.ts index db00d787..3394d1f3 100644 --- a/src/models/chaterror.ts +++ b/src/models/chaterror.ts @@ -12,8 +12,8 @@ export type Code = string | number; export type ChatErrorError = { code: string | number | null; message: string; - param: string | null; - type: string; + param?: string | null | undefined; + type?: string | null | undefined; }; /** @internal */ @@ -63,16 +63,16 @@ export const ChatErrorError$inboundSchema: z.ZodType = z.object({ code: z.nullable(z.union([z.string(), z.number()])), message: z.string(), - param: z.nullable(z.string()), - type: z.string(), + param: z.nullable(z.string()).optional(), + type: z.nullable(z.string()).optional(), }); /** @internal */ export type ChatErrorError$Outbound = { code: string | number | null; message: string; - param: string | null; - type: string; + param?: string | null | undefined; + type?: string | null | undefined; }; /** @internal */ @@ -82,8 +82,8 @@ export const ChatErrorError$outboundSchema: z.ZodType< > = z.object({ code: z.nullable(z.union([z.string(), z.number()])), message: z.string(), - param: z.nullable(z.string()), - type: z.string(), + param: z.nullable(z.string()).optional(), + type: z.nullable(z.string()).optional(), }); /** diff --git a/src/models/chatgenerationparams.ts b/src/models/chatgenerationparams.ts index b031da61..ffd3abb8 100644 --- a/src/models/chatgenerationparams.ts +++ b/src/models/chatgenerationparams.ts @@ -84,7 +84,8 @@ export type ChatGenerationParamsStop = string | Array; export type ChatGenerationParams = { messages: Array; - model: string; + model?: string | undefined; + models?: Array | undefined; frequencyPenalty?: number | null | undefined; logitBias?: { [k: string]: number } | null | undefined; logprobs?: boolean | null | undefined; @@ -493,7 +494,8 @@ export const ChatGenerationParams$inboundSchema: z.ZodType< unknown > = z.object({ messages: z.array(Message$inboundSchema), - model: z.string(), + model: z.string().optional(), + models: z.array(z.string()).optional(), frequency_penalty: z.nullable(z.number()).optional(), logit_bias: z.nullable(z.record(z.string(), z.number())).optional(), logprobs: z.nullable(z.boolean()).optional(), @@ -537,7 +539,8 @@ export const ChatGenerationParams$inboundSchema: z.ZodType< /** @internal */ export type ChatGenerationParams$Outbound = { messages: Array; - model: string; + model?: string | undefined; + models?: Array | undefined; frequency_penalty?: number | null | undefined; logit_bias?: { [k: string]: number } | null | undefined; logprobs?: boolean | null | undefined; @@ -571,7 +574,8 @@ export const ChatGenerationParams$outboundSchema: z.ZodType< ChatGenerationParams > = z.object({ messages: z.array(Message$outboundSchema), - model: z.string(), + model: z.string().optional(), + models: z.array(z.string()).optional(), frequencyPenalty: z.nullable(z.number()).optional(), logitBias: z.nullable(z.record(z.string(), z.number())).optional(), logprobs: z.nullable(z.boolean()).optional(), diff --git a/src/models/chatmessagecontentitemaudio.ts b/src/models/chatmessagecontentitemaudio.ts index ec318324..de2a5c20 100644 --- a/src/models/chatmessagecontentitemaudio.ts +++ b/src/models/chatmessagecontentitemaudio.ts @@ -26,14 +26,14 @@ export type ChatMessageContentItemAudioFormat = OpenEnum< typeof ChatMessageContentItemAudioFormat >; -export type InputAudio = { +export type ChatMessageContentItemAudioInputAudio = { data: string; format: ChatMessageContentItemAudioFormat; }; export type ChatMessageContentItemAudio = { type: "input_audio"; - inputAudio: InputAudio; + inputAudio: ChatMessageContentItemAudioInputAudio; }; /** @internal */ @@ -68,22 +68,24 @@ export namespace ChatMessageContentItemAudioFormat$ { } /** @internal */ -export const InputAudio$inboundSchema: z.ZodType = z - .object({ - data: z.string(), - format: ChatMessageContentItemAudioFormat$inboundSchema, - }); +export const ChatMessageContentItemAudioInputAudio$inboundSchema: z.ZodType< + ChatMessageContentItemAudioInputAudio, + unknown +> = z.object({ + data: z.string(), + format: ChatMessageContentItemAudioFormat$inboundSchema, +}); /** @internal */ -export type InputAudio$Outbound = { +export type ChatMessageContentItemAudioInputAudio$Outbound = { data: string; format: string; }; /** @internal */ -export const InputAudio$outboundSchema: z.ZodType< - InputAudio$Outbound, - InputAudio +export const ChatMessageContentItemAudioInputAudio$outboundSchema: z.ZodType< + ChatMessageContentItemAudioInputAudio$Outbound, + ChatMessageContentItemAudioInputAudio > = z.object({ data: z.string(), format: ChatMessageContentItemAudioFormat$outboundSchema, @@ -93,26 +95,35 @@ export const InputAudio$outboundSchema: z.ZodType< * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ -export namespace InputAudio$ { - /** @deprecated use `InputAudio$inboundSchema` instead. */ - export const inboundSchema = InputAudio$inboundSchema; - /** @deprecated use `InputAudio$outboundSchema` instead. */ - export const outboundSchema = InputAudio$outboundSchema; - /** @deprecated use `InputAudio$Outbound` instead. */ - export type Outbound = InputAudio$Outbound; +export namespace ChatMessageContentItemAudioInputAudio$ { + /** @deprecated use `ChatMessageContentItemAudioInputAudio$inboundSchema` instead. */ + export const inboundSchema = + ChatMessageContentItemAudioInputAudio$inboundSchema; + /** @deprecated use `ChatMessageContentItemAudioInputAudio$outboundSchema` instead. */ + export const outboundSchema = + ChatMessageContentItemAudioInputAudio$outboundSchema; + /** @deprecated use `ChatMessageContentItemAudioInputAudio$Outbound` instead. */ + export type Outbound = ChatMessageContentItemAudioInputAudio$Outbound; } -export function inputAudioToJSON(inputAudio: InputAudio): string { - return JSON.stringify(InputAudio$outboundSchema.parse(inputAudio)); +export function chatMessageContentItemAudioInputAudioToJSON( + chatMessageContentItemAudioInputAudio: ChatMessageContentItemAudioInputAudio, +): string { + return JSON.stringify( + ChatMessageContentItemAudioInputAudio$outboundSchema.parse( + chatMessageContentItemAudioInputAudio, + ), + ); } -export function inputAudioFromJSON( +export function chatMessageContentItemAudioInputAudioFromJSON( jsonString: string, -): SafeParseResult { +): SafeParseResult { return safeParse( jsonString, - (x) => InputAudio$inboundSchema.parse(JSON.parse(x)), - `Failed to parse 'InputAudio' from JSON`, + (x) => + ChatMessageContentItemAudioInputAudio$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ChatMessageContentItemAudioInputAudio' from JSON`, ); } @@ -122,7 +133,9 @@ export const ChatMessageContentItemAudio$inboundSchema: z.ZodType< unknown > = z.object({ type: z.literal("input_audio"), - input_audio: z.lazy(() => InputAudio$inboundSchema), + input_audio: z.lazy(() => + ChatMessageContentItemAudioInputAudio$inboundSchema + ), }).transform((v) => { return remap$(v, { "input_audio": "inputAudio", @@ -132,7 +145,7 @@ export const ChatMessageContentItemAudio$inboundSchema: z.ZodType< /** @internal */ export type ChatMessageContentItemAudio$Outbound = { type: "input_audio"; - input_audio: InputAudio$Outbound; + input_audio: ChatMessageContentItemAudioInputAudio$Outbound; }; /** @internal */ @@ -141,7 +154,9 @@ export const ChatMessageContentItemAudio$outboundSchema: z.ZodType< ChatMessageContentItemAudio > = z.object({ type: z.literal("input_audio"), - inputAudio: z.lazy(() => InputAudio$outboundSchema), + inputAudio: z.lazy(() => + ChatMessageContentItemAudioInputAudio$outboundSchema + ), }).transform((v) => { return remap$(v, { inputAudio: "input_audio", diff --git a/src/models/completioncreateparams.ts b/src/models/completioncreateparams.ts index 0ec20d17..9d1f48b0 100644 --- a/src/models/completioncreateparams.ts +++ b/src/models/completioncreateparams.ts @@ -52,7 +52,8 @@ export type CompletionCreateParamsResponseFormatUnion = | CompletionCreateParamsResponseFormatPython; export type CompletionCreateParams = { - model: string; + model?: string | undefined; + models?: Array | undefined; prompt: string | Array | Array | Array>; bestOf?: number | null | undefined; echo?: boolean | null | undefined; @@ -502,7 +503,8 @@ export const CompletionCreateParams$inboundSchema: z.ZodType< CompletionCreateParams, unknown > = z.object({ - model: z.string(), + model: z.string().optional(), + models: z.array(z.string()).optional(), prompt: z.union([ z.string(), z.array(z.string()), @@ -553,7 +555,8 @@ export const CompletionCreateParams$inboundSchema: z.ZodType< /** @internal */ export type CompletionCreateParams$Outbound = { - model: string; + model?: string | undefined; + models?: Array | undefined; prompt: string | Array | Array | Array>; best_of?: number | null | undefined; echo?: boolean | null | undefined; @@ -587,7 +590,8 @@ export const CompletionCreateParams$outboundSchema: z.ZodType< CompletionCreateParams$Outbound, CompletionCreateParams > = z.object({ - model: z.string(), + model: z.string().optional(), + models: z.array(z.string()).optional(), prompt: z.union([ z.string(), z.array(z.string()), diff --git a/src/models/index.ts b/src/models/index.ts index 98b82e15..476e47d1 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -109,6 +109,7 @@ export * from "./requesttimeoutresponseerrordata.js"; export * from "./responseformatjsonschema.js"; export * from "./responseformattextconfig.js"; export * from "./responseformattextgrammar.js"; +export * from "./responseinputaudio.js"; export * from "./responseinputfile.js"; export * from "./responseinputimage.js"; export * from "./responseinputtext.js"; diff --git a/src/models/openairesponsesinputunion.ts b/src/models/openairesponsesinputunion.ts index 77605fd7..7a29e871 100644 --- a/src/models/openairesponsesinputunion.ts +++ b/src/models/openairesponsesinputunion.ts @@ -20,6 +20,12 @@ import { OutputMessage$Outbound, OutputMessage$outboundSchema, } from "./outputmessage.js"; +import { + ResponseInputAudio, + ResponseInputAudio$inboundSchema, + ResponseInputAudio$Outbound, + ResponseInputAudio$outboundSchema, +} from "./responseinputaudio.js"; import { ResponseInputFile, ResponseInputFile$inboundSchema, @@ -111,6 +117,7 @@ export type OpenAIResponsesInputRoleUnion2 = export type OpenAIResponsesInputContent3 = | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }); export type OpenAIResponsesInputMessage2 = { @@ -123,6 +130,7 @@ export type OpenAIResponsesInputMessage2 = { content: Array< | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }) >; }; @@ -171,12 +179,14 @@ export type OpenAIResponsesInputRoleUnion1 = export type OpenAIResponsesInputContent1 = | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }); export type OpenAIResponsesInputContent2 = | Array< | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }) > | string; @@ -192,6 +202,7 @@ export type OpenAIResponsesInputMessage1 = { | Array< | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }) > | string; @@ -575,6 +586,11 @@ export const OpenAIResponsesInputContent3$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -586,6 +602,7 @@ export const OpenAIResponsesInputContent3$inboundSchema: z.ZodType< export type OpenAIResponsesInputContent3$Outbound = | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }); /** @internal */ @@ -603,6 +620,11 @@ export const OpenAIResponsesInputContent3$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -667,6 +689,11 @@ export const OpenAIResponsesInputMessage2$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -684,6 +711,7 @@ export type OpenAIResponsesInputMessage2$Outbound = { content: Array< | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }) >; }; @@ -712,6 +740,11 @@ export const OpenAIResponsesInputMessage2$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -938,6 +971,11 @@ export const OpenAIResponsesInputContent1$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -949,6 +987,7 @@ export const OpenAIResponsesInputContent1$inboundSchema: z.ZodType< export type OpenAIResponsesInputContent1$Outbound = | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }); /** @internal */ @@ -966,6 +1005,11 @@ export const OpenAIResponsesInputContent1$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -1023,6 +1067,11 @@ export const OpenAIResponsesInputContent2$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -1038,6 +1087,7 @@ export type OpenAIResponsesInputContent2$Outbound = | Array< | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }) > | string; @@ -1059,6 +1109,11 @@ export const OpenAIResponsesInputContent2$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -1127,6 +1182,11 @@ export const OpenAIResponsesInputMessage1$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -1146,6 +1206,7 @@ export type OpenAIResponsesInputMessage1$Outbound = { | Array< | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }) > | string; @@ -1176,6 +1237,11 @@ export const OpenAIResponsesInputMessage1$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, diff --git a/src/models/openairesponsesprompt.ts b/src/models/openairesponsesprompt.ts index e4f418f6..623446b9 100644 --- a/src/models/openairesponsesprompt.ts +++ b/src/models/openairesponsesprompt.ts @@ -26,18 +26,20 @@ import { } from "./responseinputtext.js"; export type Variables = - | (ResponseInputText & { type: "input_text" }) - | (ResponseInputImage & { type: "input_image" }) - | (ResponseInputFile & { type: "input_file" }); + | ResponseInputText + | ResponseInputImage + | ResponseInputFile + | string; export type OpenAIResponsesPrompt = { id: string; variables?: | { [k: string]: - | (ResponseInputText & { type: "input_text" }) - | (ResponseInputImage & { type: "input_image" }) - | (ResponseInputFile & { type: "input_file" }); + | ResponseInputText + | ResponseInputImage + | ResponseInputFile + | string; } | null | undefined; @@ -45,49 +47,28 @@ export type OpenAIResponsesPrompt = { /** @internal */ export const Variables$inboundSchema: z.ZodType = z.union([ - ResponseInputText$inboundSchema.and( - z.object({ type: z.literal("input_text") }).transform((v) => ({ - type: v.type, - })), - ), - ResponseInputImage$inboundSchema.and( - z.object({ type: z.literal("input_image") }).transform((v) => ({ - type: v.type, - })), - ), - ResponseInputFile$inboundSchema.and( - z.object({ type: z.literal("input_file") }).transform((v) => ({ - type: v.type, - })), - ), + ResponseInputText$inboundSchema, + ResponseInputImage$inboundSchema, + ResponseInputFile$inboundSchema, + z.string(), ]); /** @internal */ export type Variables$Outbound = - | (ResponseInputText$Outbound & { type: "input_text" }) - | (ResponseInputImage$Outbound & { type: "input_image" }) - | (ResponseInputFile$Outbound & { type: "input_file" }); + | ResponseInputText$Outbound + | ResponseInputImage$Outbound + | ResponseInputFile$Outbound + | string; /** @internal */ export const Variables$outboundSchema: z.ZodType< Variables$Outbound, Variables > = z.union([ - ResponseInputText$outboundSchema.and( - z.object({ type: z.literal("input_text") }).transform((v) => ({ - type: v.type, - })), - ), - ResponseInputImage$outboundSchema.and( - z.object({ type: z.literal("input_image") }).transform((v) => ({ - type: v.type, - })), - ), - ResponseInputFile$outboundSchema.and( - z.object({ type: z.literal("input_file") }).transform((v) => ({ - type: v.type, - })), - ), + ResponseInputText$outboundSchema, + ResponseInputImage$outboundSchema, + ResponseInputFile$outboundSchema, + z.string(), ]); /** @@ -127,21 +108,10 @@ export const OpenAIResponsesPrompt$inboundSchema: z.ZodType< z.record( z.string(), z.union([ - ResponseInputText$inboundSchema.and( - z.object({ type: z.literal("input_text") }).transform((v) => ({ - type: v.type, - })), - ), - ResponseInputImage$inboundSchema.and( - z.object({ type: z.literal("input_image") }).transform((v) => ({ - type: v.type, - })), - ), - ResponseInputFile$inboundSchema.and( - z.object({ type: z.literal("input_file") }).transform((v) => ({ - type: v.type, - })), - ), + ResponseInputText$inboundSchema, + ResponseInputImage$inboundSchema, + ResponseInputFile$inboundSchema, + z.string(), ]), ), ).optional(), @@ -153,9 +123,10 @@ export type OpenAIResponsesPrompt$Outbound = { variables?: | { [k: string]: - | (ResponseInputText$Outbound & { type: "input_text" }) - | (ResponseInputImage$Outbound & { type: "input_image" }) - | (ResponseInputFile$Outbound & { type: "input_file" }); + | ResponseInputText$Outbound + | ResponseInputImage$Outbound + | ResponseInputFile$Outbound + | string; } | null | undefined; @@ -171,21 +142,10 @@ export const OpenAIResponsesPrompt$outboundSchema: z.ZodType< z.record( z.string(), z.union([ - ResponseInputText$outboundSchema.and( - z.object({ type: z.literal("input_text") }).transform((v) => ({ - type: v.type, - })), - ), - ResponseInputImage$outboundSchema.and( - z.object({ type: z.literal("input_image") }).transform((v) => ({ - type: v.type, - })), - ), - ResponseInputFile$outboundSchema.and( - z.object({ type: z.literal("input_file") }).transform((v) => ({ - type: v.type, - })), - ), + ResponseInputText$outboundSchema, + ResponseInputImage$outboundSchema, + ResponseInputFile$outboundSchema, + z.string(), ]), ), ).optional(), diff --git a/src/models/openresponseseasyinputmessage.ts b/src/models/openresponseseasyinputmessage.ts index 6fb78dd5..69457d26 100644 --- a/src/models/openresponseseasyinputmessage.ts +++ b/src/models/openresponseseasyinputmessage.ts @@ -7,6 +7,12 @@ 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 { + ResponseInputAudio, + ResponseInputAudio$inboundSchema, + ResponseInputAudio$Outbound, + ResponseInputAudio$outboundSchema, +} from "./responseinputaudio.js"; import { ResponseInputFile, ResponseInputFile$inboundSchema, @@ -70,12 +76,14 @@ export type OpenResponsesEasyInputMessageRoleUnion = export type OpenResponsesEasyInputMessageContent1 = | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }); export type OpenResponsesEasyInputMessageContent2 = | Array< | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }) > | string; @@ -91,6 +99,7 @@ export type OpenResponsesEasyInputMessage = { | Array< | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }) > | string; @@ -293,6 +302,11 @@ export const OpenResponsesEasyInputMessageContent1$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -304,6 +318,7 @@ export const OpenResponsesEasyInputMessageContent1$inboundSchema: z.ZodType< export type OpenResponsesEasyInputMessageContent1$Outbound = | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }); /** @internal */ @@ -321,6 +336,11 @@ export const OpenResponsesEasyInputMessageContent1$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -381,6 +401,11 @@ export const OpenResponsesEasyInputMessageContent2$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -396,6 +421,7 @@ export type OpenResponsesEasyInputMessageContent2$Outbound = | Array< | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }) > | string; @@ -417,6 +443,11 @@ export const OpenResponsesEasyInputMessageContent2$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -488,6 +519,11 @@ export const OpenResponsesEasyInputMessage$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -507,6 +543,7 @@ export type OpenResponsesEasyInputMessage$Outbound = { | Array< | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }) > | string; @@ -537,6 +574,11 @@ export const OpenResponsesEasyInputMessage$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, diff --git a/src/models/openresponsesinputmessageitem.ts b/src/models/openresponsesinputmessageitem.ts index 68fb1207..393034c8 100644 --- a/src/models/openresponsesinputmessageitem.ts +++ b/src/models/openresponsesinputmessageitem.ts @@ -7,6 +7,12 @@ 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 { + ResponseInputAudio, + ResponseInputAudio$inboundSchema, + ResponseInputAudio$Outbound, + ResponseInputAudio$outboundSchema, +} from "./responseinputaudio.js"; import { ResponseInputFile, ResponseInputFile$inboundSchema, @@ -62,6 +68,7 @@ export type OpenResponsesInputMessageItemRoleUnion = export type OpenResponsesInputMessageItemContent = | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }); export type OpenResponsesInputMessageItem = { @@ -74,6 +81,7 @@ export type OpenResponsesInputMessageItem = { content: Array< | (ResponseInputText & { type: "input_text" }) | (ResponseInputImage & { type: "input_image" }) + | (ResponseInputAudio & { type: "input_audio" }) | (ResponseInputFile & { type: "input_file" }) >; }; @@ -248,6 +256,11 @@ export const OpenResponsesInputMessageItemContent$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -259,6 +272,7 @@ export const OpenResponsesInputMessageItemContent$inboundSchema: z.ZodType< export type OpenResponsesInputMessageItemContent$Outbound = | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }); /** @internal */ @@ -276,6 +290,11 @@ export const OpenResponsesInputMessageItemContent$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -343,6 +362,11 @@ export const OpenResponsesInputMessageItem$inboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$inboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$inboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, @@ -360,6 +384,7 @@ export type OpenResponsesInputMessageItem$Outbound = { content: Array< | (ResponseInputText$Outbound & { type: "input_text" }) | (ResponseInputImage$Outbound & { type: "input_image" }) + | (ResponseInputAudio$Outbound & { type: "input_audio" }) | (ResponseInputFile$Outbound & { type: "input_file" }) >; }; @@ -388,6 +413,11 @@ export const OpenResponsesInputMessageItem$outboundSchema: z.ZodType< type: v.type, })), ), + ResponseInputAudio$outboundSchema.and( + z.object({ type: z.literal("input_audio") }).transform((v) => ({ + type: v.type, + })), + ), ResponseInputFile$outboundSchema.and( z.object({ type: z.literal("input_file") }).transform((v) => ({ type: v.type, diff --git a/src/models/operations/createembeddings.ts b/src/models/operations/createembeddings.ts new file mode 100644 index 00000000..864a6bd7 --- /dev/null +++ b/src/models/operations/createembeddings.ts @@ -0,0 +1,1121 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; +import { + catchUnrecognizedEnum, + ClosedEnum, + OpenEnum, + Unrecognized, +} from "../../types/enums.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; +import * as models from "../index.js"; + +export type Input = + | string + | Array + | Array + | Array>; + +/** + * Data collection setting. If no available model provider meets the requirement, your request will return an error. + * + * @remarks + * - allow: (default) allow providers which store user data non-transiently and may train on it + * - deny: use only providers which do not collect user data. + */ +export const DataCollection = { + Deny: "deny", + Allow: "allow", +} as const; +/** + * Data collection setting. If no available model provider meets the requirement, your request will return an error. + * + * @remarks + * - allow: (default) allow providers which store user data non-transiently and may train on it + * - deny: use only providers which do not collect user data. + */ +export type DataCollection = OpenEnum; + +export type Order = models.ProviderName | string; + +export type Only = models.ProviderName | string; + +export type Ignore = models.ProviderName | string; + +/** + * The sorting strategy to use for this request, if "order" is not specified. When set, no load balancing is performed. + */ +export const Sort = { + Price: "price", + Throughput: "throughput", + Latency: "latency", +} as const; +/** + * The sorting strategy to use for this request, if "order" is not specified. When set, no load balancing is performed. + */ +export type Sort = OpenEnum; + +/** + * The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion. + */ +export type MaxPrice = { + /** + * A value in string or number format that is a large number + */ + prompt?: any | undefined; + /** + * A value in string or number format that is a large number + */ + completion?: any | undefined; + /** + * A value in string or number format that is a large number + */ + image?: any | undefined; + /** + * A value in string or number format that is a large number + */ + audio?: any | undefined; + /** + * A value in string or number format that is a large number + */ + request?: any | undefined; +}; + +export type Experimental = {}; + +export type CreateEmbeddingsProvider = { + /** + * Whether to allow backup providers to serve requests + * + * @remarks + * - true: (default) when the primary provider (or your custom providers in "order") is unavailable, use the next best provider. + * - false: use only the primary/custom provider, and return the upstream error if it's unavailable. + */ + allowFallbacks?: boolean | null | undefined; + /** + * Whether to filter providers to only those that support the parameters you've provided. If this setting is omitted or set to false, then providers will receive only the parameters they support, and ignore the rest. + */ + requireParameters?: boolean | null | undefined; + /** + * Data collection setting. If no available model provider meets the requirement, your request will return an error. + * + * @remarks + * - allow: (default) allow providers which store user data non-transiently and may train on it + * - deny: use only providers which do not collect user data. + */ + dataCollection?: DataCollection | null | undefined; + /** + * Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. When true, only endpoints that do not retain prompts will be used. + */ + zdr?: boolean | null | undefined; + /** + * An ordered list of provider slugs. The router will attempt to use the first provider in the subset of this list that supports your requested model, and fall back to the next if it is unavailable. If no providers are available, the request will fail with an error message. + */ + order?: Array | null | undefined; + /** + * List of provider slugs to allow. If provided, this list is merged with your account-wide allowed provider settings for this request. + */ + only?: Array | null | undefined; + /** + * List of provider slugs to ignore. If provided, this list is merged with your account-wide ignored provider settings for this request. + */ + ignore?: Array | null | undefined; + /** + * A list of quantization levels to filter the provider by. + */ + quantizations?: Array | null | undefined; + /** + * The sorting strategy to use for this request, if "order" is not specified. When set, no load balancing is performed. + */ + sort?: Sort | null | undefined; + /** + * The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion. + */ + maxPrice?: MaxPrice | undefined; + experimental?: Experimental | null | undefined; +}; + +export const EncodingFormatBase64 = { + Base64: "base64", +} as const; +export type EncodingFormatBase64 = ClosedEnum; + +export const EncodingFormatFloat = { + Float: "float", +} as const; +export type EncodingFormatFloat = ClosedEnum; + +export type EncodingFormat = EncodingFormatFloat | EncodingFormatBase64; + +export type CreateEmbeddingsRequest = { + input: string | Array | Array | Array>; + model: string; + provider?: CreateEmbeddingsProvider | undefined; + encodingFormat?: EncodingFormatFloat | EncodingFormatBase64 | undefined; + user?: string | undefined; +}; + +export const ObjectT = { + List: "list", +} as const; +export type ObjectT = ClosedEnum; + +export const ObjectEmbedding = { + Embedding: "embedding", +} as const; +export type ObjectEmbedding = ClosedEnum; + +export type Embedding = Array | string; + +export type CreateEmbeddingsData = { + object: ObjectEmbedding; + embedding: Array | string; + index?: number | undefined; +}; + +export type Usage = { + promptTokens: number; + totalTokens: number; + cost?: number | undefined; +}; + +/** + * Embedding response + */ +export type CreateEmbeddingsResponseBody = { + id?: string | undefined; + object: ObjectT; + data: Array; + model: string; + usage?: Usage | undefined; +}; + +export type CreateEmbeddingsResponse = CreateEmbeddingsResponseBody | string; + +/** @internal */ +export const Input$inboundSchema: z.ZodType = z.union([ + z.string(), + z.array(z.string()), + z.array(z.number()), + z.array(z.array(z.number())), +]); + +/** @internal */ +export type Input$Outbound = + | string + | Array + | Array + | Array>; + +/** @internal */ +export const Input$outboundSchema: z.ZodType = z.union([ + z.string(), + z.array(z.string()), + z.array(z.number()), + z.array(z.array(z.number())), +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Input$ { + /** @deprecated use `Input$inboundSchema` instead. */ + export const inboundSchema = Input$inboundSchema; + /** @deprecated use `Input$outboundSchema` instead. */ + export const outboundSchema = Input$outboundSchema; + /** @deprecated use `Input$Outbound` instead. */ + export type Outbound = Input$Outbound; +} + +export function inputToJSON(input: Input): string { + return JSON.stringify(Input$outboundSchema.parse(input)); +} + +export function inputFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Input$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Input' from JSON`, + ); +} + +/** @internal */ +export const DataCollection$inboundSchema: z.ZodType = + z + .union([ + z.enum(DataCollection), + z.string().transform(catchUnrecognizedEnum), + ]); + +/** @internal */ +export const DataCollection$outboundSchema: z.ZodType< + DataCollection, + DataCollection +> = z.union([ + z.enum(DataCollection), + z.string().and(z.custom>()), +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace DataCollection$ { + /** @deprecated use `DataCollection$inboundSchema` instead. */ + export const inboundSchema = DataCollection$inboundSchema; + /** @deprecated use `DataCollection$outboundSchema` instead. */ + export const outboundSchema = DataCollection$outboundSchema; +} + +/** @internal */ +export const Order$inboundSchema: z.ZodType = z.union([ + models.ProviderName$inboundSchema, + z.string(), +]); + +/** @internal */ +export type Order$Outbound = string | string; + +/** @internal */ +export const Order$outboundSchema: z.ZodType = z.union([ + models.ProviderName$outboundSchema, + z.string(), +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Order$ { + /** @deprecated use `Order$inboundSchema` instead. */ + export const inboundSchema = Order$inboundSchema; + /** @deprecated use `Order$outboundSchema` instead. */ + export const outboundSchema = Order$outboundSchema; + /** @deprecated use `Order$Outbound` instead. */ + export type Outbound = Order$Outbound; +} + +export function orderToJSON(order: Order): string { + return JSON.stringify(Order$outboundSchema.parse(order)); +} + +export function orderFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Order$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Order' from JSON`, + ); +} + +/** @internal */ +export const Only$inboundSchema: z.ZodType = z.union([ + models.ProviderName$inboundSchema, + z.string(), +]); + +/** @internal */ +export type Only$Outbound = string | string; + +/** @internal */ +export const Only$outboundSchema: z.ZodType = z.union([ + models.ProviderName$outboundSchema, + z.string(), +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Only$ { + /** @deprecated use `Only$inboundSchema` instead. */ + export const inboundSchema = Only$inboundSchema; + /** @deprecated use `Only$outboundSchema` instead. */ + export const outboundSchema = Only$outboundSchema; + /** @deprecated use `Only$Outbound` instead. */ + export type Outbound = Only$Outbound; +} + +export function onlyToJSON(only: Only): string { + return JSON.stringify(Only$outboundSchema.parse(only)); +} + +export function onlyFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Only$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Only' from JSON`, + ); +} + +/** @internal */ +export const Ignore$inboundSchema: z.ZodType = z.union([ + models.ProviderName$inboundSchema, + z.string(), +]); + +/** @internal */ +export type Ignore$Outbound = string | string; + +/** @internal */ +export const Ignore$outboundSchema: z.ZodType = z + .union([models.ProviderName$outboundSchema, z.string()]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Ignore$ { + /** @deprecated use `Ignore$inboundSchema` instead. */ + export const inboundSchema = Ignore$inboundSchema; + /** @deprecated use `Ignore$outboundSchema` instead. */ + export const outboundSchema = Ignore$outboundSchema; + /** @deprecated use `Ignore$Outbound` instead. */ + export type Outbound = Ignore$Outbound; +} + +export function ignoreToJSON(ignore: Ignore): string { + return JSON.stringify(Ignore$outboundSchema.parse(ignore)); +} + +export function ignoreFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Ignore$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Ignore' from JSON`, + ); +} + +/** @internal */ +export const Sort$inboundSchema: z.ZodType = z + .union([ + z.enum(Sort), + z.string().transform(catchUnrecognizedEnum), + ]); + +/** @internal */ +export const Sort$outboundSchema: z.ZodType = z.union([ + z.enum(Sort), + z.string().and(z.custom>()), +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Sort$ { + /** @deprecated use `Sort$inboundSchema` instead. */ + export const inboundSchema = Sort$inboundSchema; + /** @deprecated use `Sort$outboundSchema` instead. */ + export const outboundSchema = Sort$outboundSchema; +} + +/** @internal */ +export const MaxPrice$inboundSchema: z.ZodType = z.object({ + prompt: z.any().optional(), + completion: z.any().optional(), + image: z.any().optional(), + audio: z.any().optional(), + request: z.any().optional(), +}); + +/** @internal */ +export type MaxPrice$Outbound = { + prompt?: any | undefined; + completion?: any | undefined; + image?: any | undefined; + audio?: any | undefined; + request?: any | undefined; +}; + +/** @internal */ +export const MaxPrice$outboundSchema: z.ZodType = z + .object({ + prompt: z.any().optional(), + completion: z.any().optional(), + image: z.any().optional(), + audio: z.any().optional(), + request: z.any().optional(), + }); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace MaxPrice$ { + /** @deprecated use `MaxPrice$inboundSchema` instead. */ + export const inboundSchema = MaxPrice$inboundSchema; + /** @deprecated use `MaxPrice$outboundSchema` instead. */ + export const outboundSchema = MaxPrice$outboundSchema; + /** @deprecated use `MaxPrice$Outbound` instead. */ + export type Outbound = MaxPrice$Outbound; +} + +export function maxPriceToJSON(maxPrice: MaxPrice): string { + return JSON.stringify(MaxPrice$outboundSchema.parse(maxPrice)); +} + +export function maxPriceFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => MaxPrice$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'MaxPrice' from JSON`, + ); +} + +/** @internal */ +export const Experimental$inboundSchema: z.ZodType = z + .object({}); + +/** @internal */ +export type Experimental$Outbound = {}; + +/** @internal */ +export const Experimental$outboundSchema: z.ZodType< + Experimental$Outbound, + Experimental +> = z.object({}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Experimental$ { + /** @deprecated use `Experimental$inboundSchema` instead. */ + export const inboundSchema = Experimental$inboundSchema; + /** @deprecated use `Experimental$outboundSchema` instead. */ + export const outboundSchema = Experimental$outboundSchema; + /** @deprecated use `Experimental$Outbound` instead. */ + export type Outbound = Experimental$Outbound; +} + +export function experimentalToJSON(experimental: Experimental): string { + return JSON.stringify(Experimental$outboundSchema.parse(experimental)); +} + +export function experimentalFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Experimental$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Experimental' from JSON`, + ); +} + +/** @internal */ +export const CreateEmbeddingsProvider$inboundSchema: z.ZodType< + CreateEmbeddingsProvider, + unknown +> = z.object({ + allow_fallbacks: z.nullable(z.boolean()).optional(), + require_parameters: z.nullable(z.boolean()).optional(), + data_collection: z.nullable(DataCollection$inboundSchema).optional(), + zdr: z.nullable(z.boolean()).optional(), + order: z.nullable( + z.array(z.union([models.ProviderName$inboundSchema, z.string()])), + ).optional(), + only: z.nullable( + z.array(z.union([models.ProviderName$inboundSchema, z.string()])), + ).optional(), + ignore: z.nullable( + z.array(z.union([models.ProviderName$inboundSchema, z.string()])), + ).optional(), + quantizations: z.nullable(z.array(models.Quantization$inboundSchema)) + .optional(), + sort: z.nullable(Sort$inboundSchema).optional(), + max_price: z.lazy(() => MaxPrice$inboundSchema).optional(), + experimental: z.nullable(z.lazy(() => Experimental$inboundSchema)).optional(), +}).transform((v) => { + return remap$(v, { + "allow_fallbacks": "allowFallbacks", + "require_parameters": "requireParameters", + "data_collection": "dataCollection", + "max_price": "maxPrice", + }); +}); + +/** @internal */ +export type CreateEmbeddingsProvider$Outbound = { + allow_fallbacks?: boolean | null | undefined; + require_parameters?: boolean | null | undefined; + data_collection?: string | null | undefined; + zdr?: boolean | null | undefined; + order?: Array | null | undefined; + only?: Array | null | undefined; + ignore?: Array | null | undefined; + quantizations?: Array | null | undefined; + sort?: string | null | undefined; + max_price?: MaxPrice$Outbound | undefined; + experimental?: Experimental$Outbound | null | undefined; +}; + +/** @internal */ +export const CreateEmbeddingsProvider$outboundSchema: z.ZodType< + CreateEmbeddingsProvider$Outbound, + CreateEmbeddingsProvider +> = z.object({ + allowFallbacks: z.nullable(z.boolean()).optional(), + requireParameters: z.nullable(z.boolean()).optional(), + dataCollection: z.nullable(DataCollection$outboundSchema).optional(), + zdr: z.nullable(z.boolean()).optional(), + order: z.nullable( + z.array(z.union([models.ProviderName$outboundSchema, z.string()])), + ).optional(), + only: z.nullable( + z.array(z.union([models.ProviderName$outboundSchema, z.string()])), + ).optional(), + ignore: z.nullable( + z.array(z.union([models.ProviderName$outboundSchema, z.string()])), + ).optional(), + quantizations: z.nullable(z.array(models.Quantization$outboundSchema)) + .optional(), + sort: z.nullable(Sort$outboundSchema).optional(), + maxPrice: z.lazy(() => MaxPrice$outboundSchema).optional(), + experimental: z.nullable(z.lazy(() => Experimental$outboundSchema)) + .optional(), +}).transform((v) => { + return remap$(v, { + allowFallbacks: "allow_fallbacks", + requireParameters: "require_parameters", + dataCollection: "data_collection", + maxPrice: "max_price", + }); +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace CreateEmbeddingsProvider$ { + /** @deprecated use `CreateEmbeddingsProvider$inboundSchema` instead. */ + export const inboundSchema = CreateEmbeddingsProvider$inboundSchema; + /** @deprecated use `CreateEmbeddingsProvider$outboundSchema` instead. */ + export const outboundSchema = CreateEmbeddingsProvider$outboundSchema; + /** @deprecated use `CreateEmbeddingsProvider$Outbound` instead. */ + export type Outbound = CreateEmbeddingsProvider$Outbound; +} + +export function createEmbeddingsProviderToJSON( + createEmbeddingsProvider: CreateEmbeddingsProvider, +): string { + return JSON.stringify( + CreateEmbeddingsProvider$outboundSchema.parse(createEmbeddingsProvider), + ); +} + +export function createEmbeddingsProviderFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => CreateEmbeddingsProvider$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'CreateEmbeddingsProvider' from JSON`, + ); +} + +/** @internal */ +export const EncodingFormatBase64$inboundSchema: z.ZodEnum< + typeof EncodingFormatBase64 +> = z.enum(EncodingFormatBase64); + +/** @internal */ +export const EncodingFormatBase64$outboundSchema: z.ZodEnum< + typeof EncodingFormatBase64 +> = EncodingFormatBase64$inboundSchema; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace EncodingFormatBase64$ { + /** @deprecated use `EncodingFormatBase64$inboundSchema` instead. */ + export const inboundSchema = EncodingFormatBase64$inboundSchema; + /** @deprecated use `EncodingFormatBase64$outboundSchema` instead. */ + export const outboundSchema = EncodingFormatBase64$outboundSchema; +} + +/** @internal */ +export const EncodingFormatFloat$inboundSchema: z.ZodEnum< + typeof EncodingFormatFloat +> = z.enum(EncodingFormatFloat); + +/** @internal */ +export const EncodingFormatFloat$outboundSchema: z.ZodEnum< + typeof EncodingFormatFloat +> = EncodingFormatFloat$inboundSchema; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace EncodingFormatFloat$ { + /** @deprecated use `EncodingFormatFloat$inboundSchema` instead. */ + export const inboundSchema = EncodingFormatFloat$inboundSchema; + /** @deprecated use `EncodingFormatFloat$outboundSchema` instead. */ + export const outboundSchema = EncodingFormatFloat$outboundSchema; +} + +/** @internal */ +export const EncodingFormat$inboundSchema: z.ZodType = + z.union([ + EncodingFormatFloat$inboundSchema, + EncodingFormatBase64$inboundSchema, + ]); + +/** @internal */ +export type EncodingFormat$Outbound = string | string; + +/** @internal */ +export const EncodingFormat$outboundSchema: z.ZodType< + EncodingFormat$Outbound, + EncodingFormat +> = z.union([ + EncodingFormatFloat$outboundSchema, + EncodingFormatBase64$outboundSchema, +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace EncodingFormat$ { + /** @deprecated use `EncodingFormat$inboundSchema` instead. */ + export const inboundSchema = EncodingFormat$inboundSchema; + /** @deprecated use `EncodingFormat$outboundSchema` instead. */ + export const outboundSchema = EncodingFormat$outboundSchema; + /** @deprecated use `EncodingFormat$Outbound` instead. */ + export type Outbound = EncodingFormat$Outbound; +} + +export function encodingFormatToJSON(encodingFormat: EncodingFormat): string { + return JSON.stringify(EncodingFormat$outboundSchema.parse(encodingFormat)); +} + +export function encodingFormatFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => EncodingFormat$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'EncodingFormat' from JSON`, + ); +} + +/** @internal */ +export const CreateEmbeddingsRequest$inboundSchema: z.ZodType< + CreateEmbeddingsRequest, + unknown +> = z.object({ + input: z.union([ + z.string(), + z.array(z.string()), + z.array(z.number()), + z.array(z.array(z.number())), + ]), + model: z.string(), + provider: z.lazy(() => CreateEmbeddingsProvider$inboundSchema).optional(), + encoding_format: z.union([ + EncodingFormatFloat$inboundSchema, + EncodingFormatBase64$inboundSchema, + ]).optional(), + user: z.string().optional(), +}).transform((v) => { + return remap$(v, { + "encoding_format": "encodingFormat", + }); +}); + +/** @internal */ +export type CreateEmbeddingsRequest$Outbound = { + input: string | Array | Array | Array>; + model: string; + provider?: CreateEmbeddingsProvider$Outbound | undefined; + encoding_format?: string | string | undefined; + user?: string | undefined; +}; + +/** @internal */ +export const CreateEmbeddingsRequest$outboundSchema: z.ZodType< + CreateEmbeddingsRequest$Outbound, + CreateEmbeddingsRequest +> = z.object({ + input: z.union([ + z.string(), + z.array(z.string()), + z.array(z.number()), + z.array(z.array(z.number())), + ]), + model: z.string(), + provider: z.lazy(() => CreateEmbeddingsProvider$outboundSchema).optional(), + encodingFormat: z.union([ + EncodingFormatFloat$outboundSchema, + EncodingFormatBase64$outboundSchema, + ]).optional(), + user: z.string().optional(), +}).transform((v) => { + return remap$(v, { + encodingFormat: "encoding_format", + }); +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace CreateEmbeddingsRequest$ { + /** @deprecated use `CreateEmbeddingsRequest$inboundSchema` instead. */ + export const inboundSchema = CreateEmbeddingsRequest$inboundSchema; + /** @deprecated use `CreateEmbeddingsRequest$outboundSchema` instead. */ + export const outboundSchema = CreateEmbeddingsRequest$outboundSchema; + /** @deprecated use `CreateEmbeddingsRequest$Outbound` instead. */ + export type Outbound = CreateEmbeddingsRequest$Outbound; +} + +export function createEmbeddingsRequestToJSON( + createEmbeddingsRequest: CreateEmbeddingsRequest, +): string { + return JSON.stringify( + CreateEmbeddingsRequest$outboundSchema.parse(createEmbeddingsRequest), + ); +} + +export function createEmbeddingsRequestFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => CreateEmbeddingsRequest$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'CreateEmbeddingsRequest' from JSON`, + ); +} + +/** @internal */ +export const ObjectT$inboundSchema: z.ZodEnum = z.enum(ObjectT); + +/** @internal */ +export const ObjectT$outboundSchema: z.ZodEnum = + ObjectT$inboundSchema; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ObjectT$ { + /** @deprecated use `ObjectT$inboundSchema` instead. */ + export const inboundSchema = ObjectT$inboundSchema; + /** @deprecated use `ObjectT$outboundSchema` instead. */ + export const outboundSchema = ObjectT$outboundSchema; +} + +/** @internal */ +export const ObjectEmbedding$inboundSchema: z.ZodEnum = + z.enum(ObjectEmbedding); + +/** @internal */ +export const ObjectEmbedding$outboundSchema: z.ZodEnum = + ObjectEmbedding$inboundSchema; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ObjectEmbedding$ { + /** @deprecated use `ObjectEmbedding$inboundSchema` instead. */ + export const inboundSchema = ObjectEmbedding$inboundSchema; + /** @deprecated use `ObjectEmbedding$outboundSchema` instead. */ + export const outboundSchema = ObjectEmbedding$outboundSchema; +} + +/** @internal */ +export const Embedding$inboundSchema: z.ZodType = z.union([ + z.array(z.number()), + z.string(), +]); + +/** @internal */ +export type Embedding$Outbound = Array | string; + +/** @internal */ +export const Embedding$outboundSchema: z.ZodType< + Embedding$Outbound, + Embedding +> = z.union([z.array(z.number()), z.string()]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Embedding$ { + /** @deprecated use `Embedding$inboundSchema` instead. */ + export const inboundSchema = Embedding$inboundSchema; + /** @deprecated use `Embedding$outboundSchema` instead. */ + export const outboundSchema = Embedding$outboundSchema; + /** @deprecated use `Embedding$Outbound` instead. */ + export type Outbound = Embedding$Outbound; +} + +export function embeddingToJSON(embedding: Embedding): string { + return JSON.stringify(Embedding$outboundSchema.parse(embedding)); +} + +export function embeddingFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Embedding$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Embedding' from JSON`, + ); +} + +/** @internal */ +export const CreateEmbeddingsData$inboundSchema: z.ZodType< + CreateEmbeddingsData, + unknown +> = z.object({ + object: ObjectEmbedding$inboundSchema, + embedding: z.union([z.array(z.number()), z.string()]), + index: z.number().optional(), +}); + +/** @internal */ +export type CreateEmbeddingsData$Outbound = { + object: string; + embedding: Array | string; + index?: number | undefined; +}; + +/** @internal */ +export const CreateEmbeddingsData$outboundSchema: z.ZodType< + CreateEmbeddingsData$Outbound, + CreateEmbeddingsData +> = z.object({ + object: ObjectEmbedding$outboundSchema, + embedding: z.union([z.array(z.number()), z.string()]), + index: z.number().optional(), +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace CreateEmbeddingsData$ { + /** @deprecated use `CreateEmbeddingsData$inboundSchema` instead. */ + export const inboundSchema = CreateEmbeddingsData$inboundSchema; + /** @deprecated use `CreateEmbeddingsData$outboundSchema` instead. */ + export const outboundSchema = CreateEmbeddingsData$outboundSchema; + /** @deprecated use `CreateEmbeddingsData$Outbound` instead. */ + export type Outbound = CreateEmbeddingsData$Outbound; +} + +export function createEmbeddingsDataToJSON( + createEmbeddingsData: CreateEmbeddingsData, +): string { + return JSON.stringify( + CreateEmbeddingsData$outboundSchema.parse(createEmbeddingsData), + ); +} + +export function createEmbeddingsDataFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => CreateEmbeddingsData$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'CreateEmbeddingsData' from JSON`, + ); +} + +/** @internal */ +export const Usage$inboundSchema: z.ZodType = z.object({ + prompt_tokens: z.number(), + total_tokens: z.number(), + cost: z.number().optional(), +}).transform((v) => { + return remap$(v, { + "prompt_tokens": "promptTokens", + "total_tokens": "totalTokens", + }); +}); + +/** @internal */ +export type Usage$Outbound = { + prompt_tokens: number; + total_tokens: number; + cost?: number | undefined; +}; + +/** @internal */ +export const Usage$outboundSchema: z.ZodType = z.object({ + promptTokens: z.number(), + totalTokens: z.number(), + cost: z.number().optional(), +}).transform((v) => { + return remap$(v, { + promptTokens: "prompt_tokens", + totalTokens: "total_tokens", + }); +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Usage$ { + /** @deprecated use `Usage$inboundSchema` instead. */ + export const inboundSchema = Usage$inboundSchema; + /** @deprecated use `Usage$outboundSchema` instead. */ + export const outboundSchema = Usage$outboundSchema; + /** @deprecated use `Usage$Outbound` instead. */ + export type Outbound = Usage$Outbound; +} + +export function usageToJSON(usage: Usage): string { + return JSON.stringify(Usage$outboundSchema.parse(usage)); +} + +export function usageFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Usage$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Usage' from JSON`, + ); +} + +/** @internal */ +export const CreateEmbeddingsResponseBody$inboundSchema: z.ZodType< + CreateEmbeddingsResponseBody, + unknown +> = z.object({ + id: z.string().optional(), + object: ObjectT$inboundSchema, + data: z.array(z.lazy(() => CreateEmbeddingsData$inboundSchema)), + model: z.string(), + usage: z.lazy(() => Usage$inboundSchema).optional(), +}); + +/** @internal */ +export type CreateEmbeddingsResponseBody$Outbound = { + id?: string | undefined; + object: string; + data: Array; + model: string; + usage?: Usage$Outbound | undefined; +}; + +/** @internal */ +export const CreateEmbeddingsResponseBody$outboundSchema: z.ZodType< + CreateEmbeddingsResponseBody$Outbound, + CreateEmbeddingsResponseBody +> = z.object({ + id: z.string().optional(), + object: ObjectT$outboundSchema, + data: z.array(z.lazy(() => CreateEmbeddingsData$outboundSchema)), + model: z.string(), + usage: z.lazy(() => Usage$outboundSchema).optional(), +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace CreateEmbeddingsResponseBody$ { + /** @deprecated use `CreateEmbeddingsResponseBody$inboundSchema` instead. */ + export const inboundSchema = CreateEmbeddingsResponseBody$inboundSchema; + /** @deprecated use `CreateEmbeddingsResponseBody$outboundSchema` instead. */ + export const outboundSchema = CreateEmbeddingsResponseBody$outboundSchema; + /** @deprecated use `CreateEmbeddingsResponseBody$Outbound` instead. */ + export type Outbound = CreateEmbeddingsResponseBody$Outbound; +} + +export function createEmbeddingsResponseBodyToJSON( + createEmbeddingsResponseBody: CreateEmbeddingsResponseBody, +): string { + return JSON.stringify( + CreateEmbeddingsResponseBody$outboundSchema.parse( + createEmbeddingsResponseBody, + ), + ); +} + +export function createEmbeddingsResponseBodyFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => CreateEmbeddingsResponseBody$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'CreateEmbeddingsResponseBody' from JSON`, + ); +} + +/** @internal */ +export const CreateEmbeddingsResponse$inboundSchema: z.ZodType< + CreateEmbeddingsResponse, + unknown +> = z.union([ + z.lazy(() => CreateEmbeddingsResponseBody$inboundSchema), + z.string(), +]); + +/** @internal */ +export type CreateEmbeddingsResponse$Outbound = + | CreateEmbeddingsResponseBody$Outbound + | string; + +/** @internal */ +export const CreateEmbeddingsResponse$outboundSchema: z.ZodType< + CreateEmbeddingsResponse$Outbound, + CreateEmbeddingsResponse +> = z.union([ + z.lazy(() => CreateEmbeddingsResponseBody$outboundSchema), + z.string(), +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace CreateEmbeddingsResponse$ { + /** @deprecated use `CreateEmbeddingsResponse$inboundSchema` instead. */ + export const inboundSchema = CreateEmbeddingsResponse$inboundSchema; + /** @deprecated use `CreateEmbeddingsResponse$outboundSchema` instead. */ + export const outboundSchema = CreateEmbeddingsResponse$outboundSchema; + /** @deprecated use `CreateEmbeddingsResponse$Outbound` instead. */ + export type Outbound = CreateEmbeddingsResponse$Outbound; +} + +export function createEmbeddingsResponseToJSON( + createEmbeddingsResponse: CreateEmbeddingsResponse, +): string { + return JSON.stringify( + CreateEmbeddingsResponse$outboundSchema.parse(createEmbeddingsResponse), + ); +} + +export function createEmbeddingsResponseFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => CreateEmbeddingsResponse$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'CreateEmbeddingsResponse' from JSON`, + ); +} diff --git a/src/models/operations/getgeneration.ts b/src/models/operations/getgeneration.ts index 33d950c3..9703381f 100644 --- a/src/models/operations/getgeneration.ts +++ b/src/models/operations/getgeneration.ts @@ -129,6 +129,10 @@ export type GetGenerationData = { * Number of audio inputs in the prompt */ numInputAudioPrompt: number | null; + /** + * Number of video inputs in the prompt + */ + numVideoPrompt: number | null; /** * Number of media items in the completion */ @@ -278,6 +282,7 @@ export const GetGenerationData$inboundSchema: z.ZodType< native_tokens_cached: z.nullable(z.number()), num_media_prompt: z.nullable(z.number()), num_input_audio_prompt: z.nullable(z.number()), + num_video_prompt: z.nullable(z.number()), num_media_completion: z.nullable(z.number()), num_search_results: z.nullable(z.number()), origin: z.string(), @@ -307,6 +312,7 @@ export const GetGenerationData$inboundSchema: z.ZodType< "native_tokens_cached": "nativeTokensCached", "num_media_prompt": "numMediaPrompt", "num_input_audio_prompt": "numInputAudioPrompt", + "num_video_prompt": "numVideoPrompt", "num_media_completion": "numMediaCompletion", "num_search_results": "numSearchResults", "is_byok": "isByok", @@ -342,6 +348,7 @@ export type GetGenerationData$Outbound = { native_tokens_cached: number | null; num_media_prompt: number | null; num_input_audio_prompt: number | null; + num_video_prompt: number | null; num_media_completion: number | null; num_search_results: number | null; origin: string; @@ -381,6 +388,7 @@ export const GetGenerationData$outboundSchema: z.ZodType< nativeTokensCached: z.nullable(z.number()), numMediaPrompt: z.nullable(z.number()), numInputAudioPrompt: z.nullable(z.number()), + numVideoPrompt: z.nullable(z.number()), numMediaCompletion: z.nullable(z.number()), numSearchResults: z.nullable(z.number()), origin: z.string(), @@ -410,6 +418,7 @@ export const GetGenerationData$outboundSchema: z.ZodType< nativeTokensCached: "native_tokens_cached", numMediaPrompt: "num_media_prompt", numInputAudioPrompt: "num_input_audio_prompt", + numVideoPrompt: "num_video_prompt", numMediaCompletion: "num_media_completion", numSearchResults: "num_search_results", isByok: "is_byok", diff --git a/src/models/operations/getparameters.ts b/src/models/operations/getparameters.ts index aea44a28..eb7ca81a 100644 --- a/src/models/operations/getparameters.ts +++ b/src/models/operations/getparameters.ts @@ -17,7 +17,7 @@ export type GetParametersSecurity = { bearer: string; }; -export const Provider = { +export const GetParametersProvider = { Ai21: "AI21", AionLabs: "AionLabs", Alibaba: "Alibaba", @@ -87,12 +87,12 @@ export const Provider = { ZAi: "Z.AI", FakeProvider: "FakeProvider", } as const; -export type Provider = OpenEnum; +export type GetParametersProvider = OpenEnum; export type GetParametersRequest = { author: string; slug: string; - provider?: Provider | undefined; + provider?: GetParametersProvider | undefined; }; export const SupportedParameter = { @@ -199,15 +199,21 @@ export function getParametersSecurityFromJSON( } /** @internal */ -export const Provider$inboundSchema: z.ZodType = z +export const GetParametersProvider$inboundSchema: z.ZodType< + GetParametersProvider, + unknown +> = z .union([ - z.enum(Provider), + z.enum(GetParametersProvider), z.string().transform(catchUnrecognizedEnum), ]); /** @internal */ -export const Provider$outboundSchema: z.ZodType = z.union([ - z.enum(Provider), +export const GetParametersProvider$outboundSchema: z.ZodType< + GetParametersProvider, + GetParametersProvider +> = z.union([ + z.enum(GetParametersProvider), z.string().and(z.custom>()), ]); @@ -215,11 +221,11 @@ export const Provider$outboundSchema: z.ZodType = z.union([ * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ -export namespace Provider$ { - /** @deprecated use `Provider$inboundSchema` instead. */ - export const inboundSchema = Provider$inboundSchema; - /** @deprecated use `Provider$outboundSchema` instead. */ - export const outboundSchema = Provider$outboundSchema; +export namespace GetParametersProvider$ { + /** @deprecated use `GetParametersProvider$inboundSchema` instead. */ + export const inboundSchema = GetParametersProvider$inboundSchema; + /** @deprecated use `GetParametersProvider$outboundSchema` instead. */ + export const outboundSchema = GetParametersProvider$outboundSchema; } /** @internal */ @@ -229,7 +235,7 @@ export const GetParametersRequest$inboundSchema: z.ZodType< > = z.object({ author: z.string(), slug: z.string(), - provider: Provider$inboundSchema.optional(), + provider: GetParametersProvider$inboundSchema.optional(), }); /** @internal */ @@ -246,7 +252,7 @@ export const GetParametersRequest$outboundSchema: z.ZodType< > = z.object({ author: z.string(), slug: z.string(), - provider: Provider$outboundSchema.optional(), + provider: GetParametersProvider$outboundSchema.optional(), }); /** diff --git a/src/models/operations/index.ts b/src/models/operations/index.ts index 6649ba34..42e9912a 100644 --- a/src/models/operations/index.ts +++ b/src/models/operations/index.ts @@ -4,6 +4,7 @@ export * from "./createauthkeyscode.js"; export * from "./createcoinbasecharge.js"; +export * from "./createembeddings.js"; export * from "./createkeys.js"; export * from "./createresponses.js"; export * from "./deletekeys.js"; diff --git a/src/models/responseinputaudio.ts b/src/models/responseinputaudio.ts new file mode 100644 index 00000000..85391d13 --- /dev/null +++ b/src/models/responseinputaudio.ts @@ -0,0 +1,212 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../lib/primitives.js"; +import { safeParse } from "../lib/schemas.js"; +import { + catchUnrecognizedEnum, + ClosedEnum, + OpenEnum, + Unrecognized, +} from "../types/enums.js"; +import { Result as SafeParseResult } from "../types/fp.js"; +import { SDKValidationError } from "./errors/sdkvalidationerror.js"; + +export const ResponseInputAudioType = { + InputAudio: "input_audio", +} as const; +export type ResponseInputAudioType = ClosedEnum; + +export const ResponseInputAudioFormat = { + Mp3: "mp3", + Wav: "wav", +} as const; +export type ResponseInputAudioFormat = OpenEnum< + typeof ResponseInputAudioFormat +>; + +export type ResponseInputAudioInputAudio = { + data: string; + format: ResponseInputAudioFormat; +}; + +/** + * Audio input content item + */ +export type ResponseInputAudio = { + type: ResponseInputAudioType; + inputAudio: ResponseInputAudioInputAudio; +}; + +/** @internal */ +export const ResponseInputAudioType$inboundSchema: z.ZodEnum< + typeof ResponseInputAudioType +> = z.enum(ResponseInputAudioType); + +/** @internal */ +export const ResponseInputAudioType$outboundSchema: z.ZodEnum< + typeof ResponseInputAudioType +> = ResponseInputAudioType$inboundSchema; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ResponseInputAudioType$ { + /** @deprecated use `ResponseInputAudioType$inboundSchema` instead. */ + export const inboundSchema = ResponseInputAudioType$inboundSchema; + /** @deprecated use `ResponseInputAudioType$outboundSchema` instead. */ + export const outboundSchema = ResponseInputAudioType$outboundSchema; +} + +/** @internal */ +export const ResponseInputAudioFormat$inboundSchema: z.ZodType< + ResponseInputAudioFormat, + unknown +> = z + .union([ + z.enum(ResponseInputAudioFormat), + z.string().transform(catchUnrecognizedEnum), + ]); + +/** @internal */ +export const ResponseInputAudioFormat$outboundSchema: z.ZodType< + ResponseInputAudioFormat, + ResponseInputAudioFormat +> = z.union([ + z.enum(ResponseInputAudioFormat), + z.string().and(z.custom>()), +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ResponseInputAudioFormat$ { + /** @deprecated use `ResponseInputAudioFormat$inboundSchema` instead. */ + export const inboundSchema = ResponseInputAudioFormat$inboundSchema; + /** @deprecated use `ResponseInputAudioFormat$outboundSchema` instead. */ + export const outboundSchema = ResponseInputAudioFormat$outboundSchema; +} + +/** @internal */ +export const ResponseInputAudioInputAudio$inboundSchema: z.ZodType< + ResponseInputAudioInputAudio, + unknown +> = z.object({ + data: z.string(), + format: ResponseInputAudioFormat$inboundSchema, +}); + +/** @internal */ +export type ResponseInputAudioInputAudio$Outbound = { + data: string; + format: string; +}; + +/** @internal */ +export const ResponseInputAudioInputAudio$outboundSchema: z.ZodType< + ResponseInputAudioInputAudio$Outbound, + ResponseInputAudioInputAudio +> = z.object({ + data: z.string(), + format: ResponseInputAudioFormat$outboundSchema, +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ResponseInputAudioInputAudio$ { + /** @deprecated use `ResponseInputAudioInputAudio$inboundSchema` instead. */ + export const inboundSchema = ResponseInputAudioInputAudio$inboundSchema; + /** @deprecated use `ResponseInputAudioInputAudio$outboundSchema` instead. */ + export const outboundSchema = ResponseInputAudioInputAudio$outboundSchema; + /** @deprecated use `ResponseInputAudioInputAudio$Outbound` instead. */ + export type Outbound = ResponseInputAudioInputAudio$Outbound; +} + +export function responseInputAudioInputAudioToJSON( + responseInputAudioInputAudio: ResponseInputAudioInputAudio, +): string { + return JSON.stringify( + ResponseInputAudioInputAudio$outboundSchema.parse( + responseInputAudioInputAudio, + ), + ); +} + +export function responseInputAudioInputAudioFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ResponseInputAudioInputAudio$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ResponseInputAudioInputAudio' from JSON`, + ); +} + +/** @internal */ +export const ResponseInputAudio$inboundSchema: z.ZodType< + ResponseInputAudio, + unknown +> = z.object({ + type: ResponseInputAudioType$inboundSchema, + input_audio: z.lazy(() => ResponseInputAudioInputAudio$inboundSchema), +}).transform((v) => { + return remap$(v, { + "input_audio": "inputAudio", + }); +}); + +/** @internal */ +export type ResponseInputAudio$Outbound = { + type: string; + input_audio: ResponseInputAudioInputAudio$Outbound; +}; + +/** @internal */ +export const ResponseInputAudio$outboundSchema: z.ZodType< + ResponseInputAudio$Outbound, + ResponseInputAudio +> = z.object({ + type: ResponseInputAudioType$outboundSchema, + inputAudio: z.lazy(() => ResponseInputAudioInputAudio$outboundSchema), +}).transform((v) => { + return remap$(v, { + inputAudio: "input_audio", + }); +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ResponseInputAudio$ { + /** @deprecated use `ResponseInputAudio$inboundSchema` instead. */ + export const inboundSchema = ResponseInputAudio$inboundSchema; + /** @deprecated use `ResponseInputAudio$outboundSchema` instead. */ + export const outboundSchema = ResponseInputAudio$outboundSchema; + /** @deprecated use `ResponseInputAudio$Outbound` instead. */ + export type Outbound = ResponseInputAudio$Outbound; +} + +export function responseInputAudioToJSON( + responseInputAudio: ResponseInputAudio, +): string { + return JSON.stringify( + ResponseInputAudio$outboundSchema.parse(responseInputAudio), + ); +} + +export function responseInputAudioFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ResponseInputAudio$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ResponseInputAudio' from JSON`, + ); +} diff --git a/src/react-query/embeddingsGenerate.ts b/src/react-query/embeddingsGenerate.ts new file mode 100644 index 00000000..864b425b --- /dev/null +++ b/src/react-query/embeddingsGenerate.ts @@ -0,0 +1,89 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { + MutationKey, + useMutation, + UseMutationResult, +} from "@tanstack/react-query"; +import { OpenRouterCore } from "../core.js"; +import { embeddingsGenerate } from "../funcs/embeddingsGenerate.js"; +import { combineSignals } from "../lib/primitives.js"; +import { RequestOptions } from "../lib/sdks.js"; +import * as operations from "../models/operations/index.js"; +import { unwrapAsync } from "../types/fp.js"; +import { useOpenRouterContext } from "./_context.js"; +import { MutationHookOptions } from "./_types.js"; + +export type EmbeddingsGenerateMutationVariables = { + request: operations.CreateEmbeddingsRequest; + options?: RequestOptions; +}; + +export type EmbeddingsGenerateMutationData = + operations.CreateEmbeddingsResponse; + +/** + * Submit an embedding request + * + * @remarks + * Submits an embedding request to the embeddings router + */ +export function useEmbeddingsGenerateMutation( + options?: MutationHookOptions< + EmbeddingsGenerateMutationData, + Error, + EmbeddingsGenerateMutationVariables + >, +): UseMutationResult< + EmbeddingsGenerateMutationData, + Error, + EmbeddingsGenerateMutationVariables +> { + const client = useOpenRouterContext(); + return useMutation({ + ...buildEmbeddingsGenerateMutation(client, options), + ...options, + }); +} + +export function mutationKeyEmbeddingsGenerate(): MutationKey { + return ["@openrouter/sdk", "Embeddings", "generate"]; +} + +export function buildEmbeddingsGenerateMutation( + client$: OpenRouterCore, + hookOptions?: RequestOptions, +): { + mutationKey: MutationKey; + mutationFn: ( + variables: EmbeddingsGenerateMutationVariables, + ) => Promise; +} { + return { + mutationKey: mutationKeyEmbeddingsGenerate(), + mutationFn: function embeddingsGenerateMutationFn({ + request, + options, + }): Promise { + const mergedOptions = { + ...hookOptions, + ...options, + fetchOptions: { + ...hookOptions?.fetchOptions, + ...options?.fetchOptions, + signal: combineSignals( + hookOptions?.fetchOptions?.signal, + options?.fetchOptions?.signal, + ), + }, + }; + return unwrapAsync(embeddingsGenerate( + client$, + request, + mergedOptions, + )); + }, + }; +} diff --git a/src/react-query/index.ts b/src/react-query/index.ts index b247a736..99974a46 100644 --- a/src/react-query/index.ts +++ b/src/react-query/index.ts @@ -17,6 +17,7 @@ export * from "./chatSend.js"; export * from "./completionsGenerate.js"; export * from "./creditsCreateCoinbaseCharge.js"; export * from "./creditsGetCredits.js"; +export * from "./embeddingsGenerate.js"; export * from "./endpointsList.js"; export * from "./endpointsListZdrEndpoints.js"; export * from "./generationsGetGeneration.js"; diff --git a/src/react-query/parametersGetParameters.ts b/src/react-query/parametersGetParameters.ts index cb39fd26..c0dd28c2 100644 --- a/src/react-query/parametersGetParameters.ts +++ b/src/react-query/parametersGetParameters.ts @@ -87,7 +87,7 @@ export function setParametersGetParametersData( queryKeyBase: [ author: string, slug: string, - parameters: { provider?: operations.Provider | undefined }, + parameters: { provider?: operations.GetParametersProvider | undefined }, ], data: ParametersGetParametersQueryData, ): ParametersGetParametersQueryData | undefined { @@ -102,7 +102,7 @@ export function invalidateParametersGetParameters( [ author: string, slug: string, - parameters: { provider?: operations.Provider | undefined }, + parameters: { provider?: operations.GetParametersProvider | undefined }, ] >, filters?: Omit, @@ -165,7 +165,7 @@ export function buildParametersGetParametersQuery( export function queryKeyParametersGetParameters( author: string, slug: string, - parameters: { provider?: operations.Provider | undefined }, + parameters: { provider?: operations.GetParametersProvider | undefined }, ): QueryKey { return [ "@openrouter/sdk", diff --git a/src/sdk/embeddings.ts b/src/sdk/embeddings.ts new file mode 100644 index 00000000..c30abe54 --- /dev/null +++ b/src/sdk/embeddings.ts @@ -0,0 +1,27 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { embeddingsGenerate } from "../funcs/embeddingsGenerate.js"; +import { ClientSDK, RequestOptions } from "../lib/sdks.js"; +import * as operations from "../models/operations/index.js"; +import { unwrapAsync } from "../types/fp.js"; + +export class Embeddings extends ClientSDK { + /** + * Submit an embedding request + * + * @remarks + * Submits an embedding request to the embeddings router + */ + async generate( + request: operations.CreateEmbeddingsRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(embeddingsGenerate( + this, + request, + options, + )); + } +} diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 8c70c802..1c6677a3 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -9,6 +9,7 @@ import { Beta } from "./beta.js"; import { Chat } from "./chat.js"; import { Completions } from "./completions.js"; import { Credits } from "./credits.js"; +import { Embeddings } from "./embeddings.js"; import { Endpoints } from "./endpoints.js"; import { Generations } from "./generations.js"; import { Models } from "./models.js"; @@ -32,6 +33,11 @@ export class OpenRouter extends ClientSDK { return (this._credits ??= new Credits(this._options)); } + private _embeddings?: Embeddings; + get embeddings(): Embeddings { + return (this._embeddings ??= new Embeddings(this._options)); + } + private _generations?: Generations; get generations(): Generations { return (this._generations ??= new Generations(this._options));