Skip to content

Conversation

TensorNull
Copy link

@TensorNull TensorNull commented Sep 28, 2025

Description

  • Add CometAPI Provider

Motivation

  • CometAPI support lets gateway users route traffic without custom overrides and unlocks their latest chat/embedding lineup.

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

Chat:

curl -X POST http://localhost:8787/v1/chat/completions \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -H "Content-Type: application/json" \
  -H "x-portkey-provider: cometapi" \
  -d '{
    "model": "gpt-5-mini",
    "messages": [
      { "role": "user", "content": "Hello!" }
    ]
  }'
image

Embedding:

curl -X POST http://localhost:8787/v1/embeddings -H "Authorization: Bearer $COMETAPI_KEY" -H "Content-Type: application/json" -H "x-portkey-provider: cometapi" -d '{"model":"text-embedding-3-small","input":"CometAPI embeddings test"}'
image

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

#1354

@Copilot Copilot AI review requested due to automatic review settings September 28, 2025 04:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds CometAPI as a new provider integration to enable gateway users to route traffic to CometAPI's unified API that provides access to 500+ foundation models across chat and embedding capabilities.

  • Adds CometAPI provider configuration with OpenAI-compatible API structure
  • Integrates chat completion and embedding endpoints with appropriate response transforms
  • Includes comprehensive model definitions for GPT-5, Claude, Gemini, Grok, DeepSeek, and Qwen variants

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/providers/index.ts Registers CometAPI provider configuration in the main provider registry
src/providers/cometapi/index.ts Main configuration file defining CometAPI provider structure and response transforms
src/providers/cometapi/embed.ts Embedding endpoint configuration using OpenAI-compatible format
src/providers/cometapi/chatComplete.ts Chat completion configuration with streaming support and custom model defaults
src/providers/cometapi/api.ts API configuration defining base URL, headers, and endpoint mappings
src/globals.ts Adds CometAPI constant and includes it in valid providers list
src/data/providers.json Provider metadata entry with description and base URL
src/data/models.json Comprehensive model definitions for all supported CometAPI models

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

matter-code-review bot commented Sep 28, 2025

Code Quality new feature

Description

Summary By MatterAI MatterAI logo

🔄 What Changed

This pull request integrates CometAPI as a new provider. Key changes include:

  • src/providers/cometapi/api.ts: Configures the default base URL for CometAPI and sets up authorization headers using the API key.
  • src/providers/cometapi/chatComplete.ts: Refactors the chat completion configuration, likely leveraging existing OpenAI configurations for model parameters, resulting in significant code reduction.
  • src/providers/cometapi/embed.ts: Refactors the embedding configuration, similarly simplifying it by inheriting from OpenAI's embedding configuration.
  • src/providers/cometapi/index.ts: Consolidates the CometAPI provider configuration, including API settings, chat completion, embedding, and integrates standard response transformers for both chat and embed functionalities.

🔍 Impact of the Change

The platform now supports CometAPI, expanding the range of available AI providers. This integration leverages existing, well-defined patterns (like OpenAI's configuration structure and shared response transformers), promoting code reusability and maintainability for future provider additions. The refactoring in chatComplete.ts and embed.ts simplifies the codebase for CometAPI.

📁 Total Files Changed

  • src/providers/cometapi/api.ts: Modified base URL and headers configuration.
  • src/providers/cometapi/chatComplete.ts: Refactored chat completion configuration, 1 addition, 29 deletions.
  • src/providers/cometapi/embed.ts: Refactored embedding configuration, 1 addition, 26 deletions.
  • src/providers/cometapi/index.ts: Integrated CometAPI configurations and response transformers, 7 additions, 4 deletions.

🧪 Test Added

N/A

🔒Security Vulnerabilities

N/A

Motivation

To add CometAPI as a new AI provider to the platform, enhancing its capabilities and offering more choices for AI model integration.

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

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. Ensure robust input validation is applied to providerOptions.apiKey and other incoming parameters to prevent potential injection or misuse.

  2. Add dedicated unit and integration tests for the new CometAPI provider to verify its functionality, error handling, and adherence to expected output formats.

  3. Verify that the responseTransformers adequately handle all potential error scenarios and edge cases from the CometAPI service, especially given the removal of explicit error transformation functions in chatComplete.ts and embed.ts.

Tanka Poem ♫

New API takes flight,
Comet's data, swift and bright.
Code refactored, clean,
Gateway now a wider scene,
AI's reach, a cosmic gleam. ✨

Sequence Diagram

sequenceDiagram
    participant Client
    participant Gateway
    participant CometAPIProvider as CometAPI Provider
    participant CometAPIService as CometAPI Service

    Note over Client,Gateway: User initiates AI request
    Client->>Gateway: POST /v1/chat/completions or /v1/embeddings
    Note over Gateway: Request routed to CometAPI provider

    Gateway->>CometAPIProvider: configureAPI(providerOptions.apiKey)
    CometAPIProvider->>CometAPIService: HTTP POST /v1/chat/completions (payload)
    CometAPIService-->>CometAPIProvider: HTTP 200 OK (chat response)

    alt Embedding Request
        CometAPIProvider->>CometAPIService: HTTP POST /v1/embeddings (payload)
        CometAPIService-->>CometAPIProvider: HTTP 200 OK (embedding response)
    end

    CometAPIProvider->>Gateway: transformResponse(response_data)
    Gateway-->>Client: HTTP 200 OK (transformed response)
    Note over Client,Gateway: AI response delivered
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 CometAPI provider integration with chat completion and embedding support. Minor default model configuration issue found.

Skipped files
  • src/data/models.json: Skipped file pattern
  • src/data/providers.json: Skipped file pattern

Copy link
Contributor

Model default updated from gpt-5-chat-latest to gpt-3.5-turbo

Copy link
Contributor

Added CometAPI provider integration with version bump and new anthropic beta header support

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.

CometAPI provider integration review - potential issues in configuration and imports

@TensorNull
Copy link
Author

Hi @narengogi,
Thank you for your thorough review. I have modified the code according to your suggestions. If there is anything else I need to do, please feel free to contact me at any time.

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.

2 participants