Skip to content

Conversation

@code-crusher
Copy link
Contributor

@code-crusher code-crusher commented Oct 27, 2025

Description

Add MatterAI Provider with Axon models. MatterAI launched it's 3 new models, Axon, Axon Mini and Axon Code. More details on the website: https://www.matterai.so and docs: https://docs.matterai.so

Manual Test

Request

curl -X POST http://localhost:8787/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "x-portkey-provider: matterai" \
  -H "Authorization: Bearer mttr_sk-mai-XXXX" \
  -d '{
    "model": "axon-mini",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Response

{
    "id": "chatcmpl-fbb1fd78-35d1-4c4e-9cde-6f101972f4bf",
    "choices": [
        {
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null,
            "matched_stop": 151645,
            "message": {
                "content": "Hello! How can I assist you today?",
                "reasoning_content": null,
                "role": "assistant",
                "tool_calls": null
            }
        }
    ],
    "created": 1761537529,
    "model": "axon-code",
    "object": "chat.completion",
    "usage": {
        "prompt_tokens": 12,
        "completion_tokens": 73,
        "total_tokens": 85,
        "completion_tokens_details": {
            "reasoning_tokens": 63
        },
        "prompt_tokens_details": {
            "cached_tokens": 0
        }
    }
}

Motivation

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)

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

@matter-code-review
Copy link
Contributor

Code Quality new feature

Summary By MatterAI MatterAI logo

🔄 What Changed

Added support for a new AI provider, MatterAI, including configuration, API integration, and streaming chat completion logic. The provider is now registered globally and integrated into the existing provider registry.

🔍 Impact of the Change

Enables the system to interface with the MatterAI API for chat completions, expanding available LLM options. Minimal risk to existing functionality due to isolated module addition.

📁 Total Files Changed

File ChangeLog
New Constant src/globals.ts Added MATTERAI constant and included in provider list
New Import src/providers/index.ts Imported MatterAIConfig and registered in provider map
New API Config src/providers/matterai/api.ts Defined base URL, headers, and endpoint routing for MatterAI API
New Chat Logic src/providers/matterai/chatComplete.ts Implemented chat config and stream chunk transformation with error handling
New Module src/providers/matterai/index.ts Aggregated and exported MatterAI provider components

🧪 Test Added/Recommended

Recommended

  • Add unit tests for MatterAIChatCompleteStreamChunkTransform to validate parsing, error handling, and transformation of stream chunks.
  • Add integration test to verify full chat completion flow with mocked MatterAI API.
  • Add validation test for getEndpoint in MatterAIAPIConfig to ensure correct routing for chatComplete and stream-chatComplete.

🔒 Security Vulnerabilities

No security vulnerabilities detected. API key handling follows existing secure pattern via Authorization header.

⏳ Estimated code review effort

LOW (~7 minutes)

Tip

Quality Recommendations

  1. Add unit tests for MatterAIChatCompleteStreamChunkTransform to cover edge cases like empty chunks, [DONE] signal, and malformed JSON

  2. Add input validation in headers() to ensure providerOptions.apiKey is present and non-empty

  3. Include timeout and retry logic in API config for resilience

  4. Add JSDoc comments to MatterAIChatCompleteConfig and stream transform function for clarity

  5. Validate that default model 'axon' is supported by MatterAI API via documentation or test

♫ Tanka Poem

New provider takes flight,
MatterAI joins the stream flow,
Tokens dance in response,
Code hums with quiet pride—
Future models, open doors. 🚀

Sequence Diagram

sequenceDiagram
    participant Client
    participant Providers as Provider Registry
    participant MatterAI as MatterAIConfig
    participant API as MatterAIAPIConfig
    participant Chat as MatterAIChatCompleteConfig
    participant Stream as StreamChunkTransform

    Note over Client,Providers: Initialization

    Client->>Providers: Request provider 'matterai'
    Providers-->>Client: Returns MatterAIConfig

    MatterAI->>API: getBaseURL()
    API-->>MatterAI: https://api.matterai.so/v1

    MatterAI->>API: headers({ apiKey })
    API-->>MatterAI: { Authorization: Bearer <key> }

    MatterAI->>API: getEndpoint(fn='chatComplete')
    API-->>MatterAI: /chat/completions

    MatterAI->>Chat: Use model config (default: 'axon')

    Note over Stream: Streaming Response Handling

    Client->>Stream: Receive stream chunk
    Stream->>Stream: Parse JSON, validate structure
    alt Valid Chunk
        Stream-->>Client: data: { ...chunk, provider: 'matterai' }
\n
    else Parse Error
        Stream-->>globalConsole: Log error
        Stream-->>Client: Forward raw chunk
    end
Loading

@matter-code-review
Copy link
Contributor

✅ Reviewed the changes: Review of MatterAI provider integration

@code-crusher
Copy link
Contributor Author

@narengogi for review

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.

1 participant