Skip to content

provider: added support for Hyperbolic AI #1108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2025

Conversation

Utkarsh-0304
Copy link
Contributor

Description

Added Hyperbolic provider support, including API configuration and response transforms for chat completion and image generation.

Motivation

This adds support for the Hyperbolic provider as requested in issue #672

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)

Related Issues

Fixes #672

Copy link
Collaborator

@narengogi narengogi left a comment

Choose a reason for hiding this comment

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

looks good, just need to remove the boilerplate

} from './imageGenerate';

const HyperbolicConfig: ProviderConfigs = {
chatComplete: HyperbolicChatCompleteConfig,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can see in the documentation that the chat completions endpoint is openai compliant, you can use the transformers for openai-base and avoid the boilerplate
checkout the implementation for any of groq, x-ai, nebius etc.
the open-ai-base package has the implementation

example PR: https://github.com/Portkey-AI/gateway/pull/801/files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review! I'm working on the requested changes and will update the pull request soon.

Copy link

matter-code-review bot commented May 27, 2025

Code Quality new feature

Description

Summary By MatterAI MatterAI logo

🔄 What Changed

This pull request introduces comprehensive support for Hyperbolic AI as a new provider. Key changes include:

  • Global Constants: Added HYPERBOLIC constant to src/globals.ts and included it in VALID_PROVIDERS.
  • API Configuration: Created src/providers/hyperbolic/api.ts to define the base URL (https://api.hyperbolic.xyz), authentication headers (Bearer token), and API endpoints for chatComplete (/v1/chat/completions) and imageGenerate (/v1/image/generation).
  • Chat Completion Stream Transform: Implemented src/providers/hyperbolic/chatComplete.ts with HyperbolicChatCompleteStreamChunkTransform to parse and reformat streaming chat completion responses from Hyperbolic AI into a standardized format.
  • Image Generation Configuration and Transform: Added src/providers/hyperbolic/imageGenerate.ts which defines HyperbolicImageGenerateConfig for image generation parameters (model, prompt, height, width, backend) and HyperbolicImageGenerateResponseTransform for processing image generation responses, including error handling via OpenAIErrorResponseTransform.
  • Provider Integration: Consolidated all Hyperbolic-specific configurations in src/providers/hyperbolic/index.ts, including chat completion parameters (with top_k, min_p, repetition_penalty), image generation config, API config, and response transformers. This file is then imported and added to the main Providers object in src/providers/index.ts.

🔍 Impact of the Change

This change significantly expands the platform's capabilities by integrating a new AI provider, Hyperbolic AI. Users can now leverage Hyperbolic AI for both chat completion and image generation tasks, offering more flexibility and choice in AI models. The structured integration ensures maintainability and consistency with existing provider patterns.

📁 Total Files Changed

  • Total Files: 6
  • Additions: 170 lines
  • Deletions: 0 lines

🧪 Test Added(explain each test in detail)

No explicit tests were added or described in the pull request. Manual testing is presumed to have been performed to verify the functionality of the new Hyperbolic AI integration for chat completion and image generation.

🔒Security Vulnerabilities

No new security vulnerabilities were detected in the provided code changes. The API key handling follows standard bearer token authentication, which is secure when the key is managed properly.

Motivation

Adding support for a new AI provider, Hyperbolic AI, to expand the platform's capabilities for chat completion and image generation.

Type of Change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

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

Related Issues

N/A

Tip

Quality Recommendations

  1. The catch block in HyperbolicChatCompleteStreamChunkTransform logs an error but still returns the raw chunk as data: ${chunk}\n\n. If JSON.parse(chunk) fails, the client might receive malformed JSON or unexpected data. Consider returning an error message in a standardized format or skipping the chunk if it's unparseable, depending on the desired client behavior.

  2. While OpenAIErrorResponseTransform is used for imageGenerate, it's crucial to verify that Hyperbolic's error response structure is consistently identical to OpenAI's. If not, a dedicated HyperbolicErrorResponseTransform should be implemented to ensure accurate error parsing and consistent error messages for the client.

  3. No new unit or integration tests were added for the Hyperbolic provider. It's essential to add tests for HyperbolicAPIConfig, HyperbolicChatCompleteStreamChunkTransform, and HyperbolicImageGenerateResponseTransform to ensure their correctness and robustness, as well as end-to-end integration tests.

  4. Update the project's documentation (e.g., README.md or a dedicated PROVIDERS.md) to include Hyperbolic AI as a supported provider, detailing its capabilities, required API keys, and any specific configuration options.

Sequence Diagram

sequenceDiagram
    actor User
    participant ClientApplication
    participant ProvidersEntrypoint as src/providers/index.ts
    participant HyperbolicConfig as src/providers/hyperbolic/index.ts
    participant HyperbolicAPIConfig as src/providers/hyperbolic/api.ts
    participant HyperbolicAIApi as Hyperbolic AI API
    participant ChatCompleteTransform as src/providers/hyperbolic/chatComplete.ts
    participant ImageGenerateTransform as src/providers/hyperbolic/imageGenerate.ts

    User->>ClientApplication: Initiates AI Request (e.g., chatComplete, imageGenerate)
    ClientApplication->>ProvidersEntrypoint: Call Provider (provider: 'hyperbolic', fn: 'chatComplete'/'imageGenerate', params)
    ProvidersEntrypoint->>HyperbolicConfig: Route to HyperbolicConfig
    HyperbolicConfig->>HyperbolicAPIConfig: Get API Configuration (fn)
    HyperbolicAPIConfig-->>HyperbolicConfig: Returns baseURL, headers, endpoint (e.g., '/v1/chat/completions' or '/v1/image/generation')
    HyperbolicConfig->>HyperbolicAIApi: Make API Call (POST baseURL + endpoint, headers, body)
    HyperbolicAIApi-->>HyperbolicConfig: Returns Response (stream or JSON)

    alt If chatComplete and streaming
        HyperbolicConfig->>ChatCompleteTransform: Transform Stream Chunk (responseChunk)
        ChatCompleteTransform-->>HyperbolicConfig: Returns Transformed Chunk (data: { ... }
\n)
    else If imageGenerate
        HyperbolicConfig->>ImageGenerateTransform: Transform Image Response (response, responseStatus)
        ImageGenerateTransform-->>HyperbolicConfig: Returns Transformed Response
    end

    HyperbolicConfig-->>ProvidersEntrypoint: Returns Processed Response
    ProvidersEntrypoint-->>ClientApplication: Returns Final Response
    ClientApplication-->>User: Displays AI Output
Loading

Copy link

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@Utkarsh-0304
Copy link
Contributor Author

@narengogi, I have made the necessary changes.

Just had one question about the documentation, parameters frequency_penalty and presence_penalty have different value ranges from the OpenAI docs.

Also, I have added extra params ( top_k, min_p, repetition_penalty ) which were not present in openai listed params.

Please take a look and let me know if anything else is needed.

Copy link

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@Utkarsh-0304 Utkarsh-0304 requested a review from narengogi May 28, 2025 06:38
@narengogi narengogi requested a review from b4s36t4 May 29, 2025 05:39
Copy link

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@VisargD VisargD merged commit a314f5f into Portkey-AI:main Jun 11, 2025
2 checks passed
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.

[Provider] Support for Hyperbolic AI
3 participants