Skip to content

Conversation

@saicherry93479
Copy link

Description

This PR adds VeenaMAX TTS (Text-to-Speech) provider integration

Type of Change

Changes Made
Core Integration Files
src/providers/veenamax/api.ts - API configuration with base URL, headers, and endpoint mapping
src/providers/veenamax/createSpeech.ts - TTS implementation with parameter mapping and response transformation
src/providers/veenamax/index.ts - Main provider configuration export
src/globals.ts - Added VEENA_MAX constant
src/providers/index.ts - Registered VeenaMAX provider

How Has This Been Tested?

src/providers/veenamax/api.test.ts - Tests API configuration, headers, and endpoint mapping
src/providers/veenamax/createSpeech.test.ts - Tests TTS functionality, error handling, and voice mappings

Basic TTS request

curl --location 'http://localhost:8787/v1/audio/speech'
--header 'Content-Type: application/json'
--header 'x-portkey-provider: veenamax'
--header 'Authorization: Bearer your_veenamax_api_key'
--data '{
"input": "Hello! This is a REST API test of VeenaMAX TTS through Portkey Gateway.",
"voice": "charu_soft",
"response_format": "wav"
}'

image

@matter-code-review
Copy link
Contributor

Code Quality new feature

Description

Summary By MatterAI MatterAI logo

🔄 What Changed

This pull request integrates the new VeenaMAX Text-to-Speech (TTS) provider into the system. It involves defining a new global constant for VeenaMAX, registering the provider within the existing provider index, and creating dedicated files for its API configuration, parameter mapping, and response transformation logic. The integration includes handling various API responses and errors from the VeenaMAX service.

🔍 Impact of the Change

This change expands the platform's capabilities by adding a new TTS provider, offering more options for speech generation. The structured integration ensures maintainability and consistent error handling across providers. It introduces new external API calls to https://flash.mayaresearch.ai/generate for speech synthesis.

📁 Total Files Changed

  • src/globals.ts: Added VEENA_MAX constant and included it in VALID_PROVIDERS list.
  • src/providers/index.ts: Imported VeenaMaxConfig and registered it in the Providers object.
  • src/providers/veenamax/api.ts: New file defining the base URL, authentication headers, and endpoint for VeenaMAX API calls.
  • src/providers/veenamax/createSpeech.ts: New file containing request/response interfaces, parameter mapping (VeenaMaxCreateSpeechConfig), and comprehensive response transformation/error handling logic (VeenaMaxCreateSpeechResponseTransform).
  • src/providers/veenamax/index.ts: New file serving as the entry point for the VeenaMAX provider, consolidating its API, speech creation configuration, and response transforms.

🧪 Test Added

No explicit test files were added in this PR. The existing test suite should be extended to cover the new VeenaMAX provider integration, specifically for successful speech creation and various error scenarios.

🔒Security Vulnerabilities

The Authorization header is correctly implemented using a Bearer token derived from providerOptions.apiKey. The code handles various HTTP error statuses, including 401 (authentication_error) and 403 (permission_error), which is good practice. No direct security vulnerabilities are introduced by the provided code snippets, assuming providerOptions.apiKey is securely managed and passed to the gateway.

Motivation

Integration of a new Text-to-Speech provider to expand service offerings and capabilities.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing (Assumed for new provider integration)

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Tip

Quality Recommendations

  1. Implement explicit input validation at the gateway level for text and speaker_id parameters before forwarding to the VeenaMAX API to ensure data integrity and prevent malformed requests.

  2. Add comprehensive unit tests for the VeenaMaxCreateSpeechResponseTransform function to cover all success and error response scenarios, ensuring robust error handling.

  3. Enhance logging to include the full error message and response body received from the VeenaMAX service when an error occurs, which will aid in debugging and troubleshooting.

Tanka Poem ♫

New voice takes its stage,
Bits of sound, a flowing stream,
Code now sings with grace.
API's dance, a sweet new tune,
Science whispers, "Well done!" 🎶

Sequence Diagram

sequenceDiagram
    participant Client
    participant GatewayAPI as Gateway API
    participant VeenaMAX as VeenaMAX TTS Service

    Client->>GatewayAPI: POST /v1/speech/create (input: string, voice: string, model: string, ...)
    Note over GatewayAPI: Route request to VeenaMAX provider
    GatewayAPI->>GatewayAPI: Map parameters using VeenaMaxCreateSpeechConfig
    GatewayAPI->>GatewayAPI: Get API endpoint from VeenaMaxAPIConfig.getEndpoint({fn: 'createSpeech'})
    GatewayAPI->>GatewayAPI: Prepare headers with Authorization: Bearer {apiKey} from VeenaMaxAPIConfig.headers
    GatewayAPI->>VeenaMAX: POST https://flash.mayaresearch.ai/generate (text: string, speaker_id: string, streaming?: boolean, normalize?: boolean)
    alt Successful Response (HTTP 200 OK)
        VeenaMAX-->>GatewayAPI: Audio Data (e.g., WAV format)
        GatewayAPI->>GatewayAPI: Transform response using VeenaMaxCreateSpeechResponseTransform(audioData, 200)
        GatewayAPI-->>Client: 200 OK (Audio Data)
    else Error Response (HTTP 4xx/5xx)
        VeenaMAX-->>GatewayAPI: Error JSON (error: {message, code, type})
        GatewayAPI->>GatewayAPI: Transform error using VeenaMaxCreateSpeechResponseTransform(errorJSON, statusCode)
        GatewayAPI->>GatewayAPI: Generate standardized error response via generateErrorResponse(...)
        GatewayAPI-->>Client: Error Response (e.g., 400 Bad Request, 401 Unauthorized)
    end
Loading

Copy link
Contributor

@matter-code-review matter-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New TTS provider integration for VeenaMAX. Code structure follows existing patterns but has critical error handling issues.

Comment on lines +83 to +84
code:
errorResponse.error.code?.toString() || responseStatus.toString(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug Fix

Issue: Error response handling fails when errorResponse.error.code is 0 (falsy), causing undefined in error code
Fix: Use nullish coalescing to handle 0 correctly
Impact: Prevents incorrect error codes in API responses

Suggested change
code:
errorResponse.error.code?.toString() || responseStatus.toString(),
code:
errorResponse.error.code ?? responseStatus.toString(),

) => {
if (responseStatus !== 200) {
if (response && typeof response === 'object' && 'error' in response) {
const errorResponse = response as VeenaMaxErrorResponse;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Redundant type assertion after in operator check
Fix: Remove unnecessary type assertion since in operator already confirms type
Impact: Cleaner code without runtime impact

Suggested change
const errorResponse = response as VeenaMaxErrorResponse;
const errorResponse = response;


switch (responseStatus) {
case 400:
errorMessage =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @saicherry93479 I would not recommend keeping a map of the error messages here in the gateway, please forward whatever error message is returned from the upstream provider in the https response

@VisargD
Copy link
Collaborator

VisargD commented Nov 6, 2025

Hi @saicherry93479 , would you be able to address the comments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants