Skip to main content

TraceAI MiniMax Instrumentation

OpenTelemetry instrumentation for MiniMax - chat completions via the OpenAI-compatible API.

Installation

pip install traceai-minimax

Features

  • Automatic tracing of MiniMax API calls via OpenAI SDK
  • Support for MiniMax-M2.7, MiniMax-M2.7-highspeed, MiniMax-M2.5, and MiniMax-M2.5-highspeed models
  • Streaming response support
  • Token usage tracking
  • Function/tool calling support
  • Full OpenTelemetry semantic conventions compliance

Usage

Basic Setup

from openai import OpenAI
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

from traceai_minimax import MiniMaxInstrumentor

# Set up tracing
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
trace.set_tracer_provider(provider)

# Instrument MiniMax
MiniMaxInstrumentor().instrument(tracer_provider=provider)

# Use MiniMax via OpenAI SDK
client = OpenAI(
    api_key="your-minimax-api-key",
    base_url="https://api.minimax.io/v1"
)

response = client.chat.completions.create(
    model="MiniMax-M2.7",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

MiniMax Chat

from openai import OpenAI

client = OpenAI(
    api_key="your-minimax-api-key",
    base_url="https://api.minimax.io/v1"
)

# Simple chat
response = client.chat.completions.create(
    model="MiniMax-M2.7",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is machine learning?"}
    ],
    temperature=0.7,
    max_tokens=1024
)
print(response.choices[0].message.content)

Streaming Responses

from openai import OpenAI

client = OpenAI(
    api_key="your-minimax-api-key",
    base_url="https://api.minimax.io/v1"
)

# Streaming chat
stream = client.chat.completions.create(
    model="MiniMax-M2.7",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()

Function Calling / Tools

from openai import OpenAI
import json

client = OpenAI(
    api_key="your-minimax-api-key",
    base_url="https://api.minimax.io/v1"
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather for a location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city name"
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                        "description": "Temperature unit"
                    }
                },
                "required": ["location"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="MiniMax-M2.7",
    messages=[{"role": "user", "content": "What's the weather in Paris?"}],
    tools=tools,
    tool_choice="auto"
)

message = response.choices[0].message
if message.tool_calls:
    for tool_call in message.tool_calls:
        print(f"Function: {tool_call.function.name}")
        print(f"Arguments: {tool_call.function.arguments}")

Async Usage

import asyncio
from openai import AsyncOpenAI

async def main():
    client = AsyncOpenAI(
        api_key="your-minimax-api-key",
        base_url="https://api.minimax.io/v1"
    )

    response = await client.chat.completions.create(
        model="MiniMax-M2.7",
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(response.choices[0].message.content)

asyncio.run(main())

JSON Mode

from openai import OpenAI

client = OpenAI(
    api_key="your-minimax-api-key",
    base_url="https://api.minimax.io/v1"
)

response = client.chat.completions.create(
    model="MiniMax-M2.7",
    messages=[
        {"role": "system", "content": "Output valid JSON only."},
        {"role": "user", "content": "List 3 programming languages with their main use cases"}
    ],
    response_format={"type": "json_object"}
)

import json
data = json.loads(response.choices[0].message.content)
print(data)

Configuration Options

TraceConfig

from fi_instrumentation import TraceConfig
from traceai_minimax import MiniMaxInstrumentor

config = TraceConfig(
    hide_inputs=False,
    hide_outputs=False,
)

MiniMaxInstrumentor().instrument(
    tracer_provider=provider,
    config=config
)

Captured Attributes

Common Attributes

Attribute Description
fi.span.kind "LLM"
llm.system "minimax"
llm.provider "minimax"
llm.model Model name (MiniMax-M2.7, MiniMax-M2.7-highspeed, MiniMax-M2.5, MiniMax-M2.5-highspeed)
llm.token_count.prompt Input token count
llm.token_count.completion Output token count
llm.token_count.total Total token count

MiniMax-Specific Attributes

Attribute Description
minimax.response_id Unique response ID
minimax.finish_reason Response finish reason (stop, tool_calls, length)
minimax.tool_calls_count Number of tool calls
minimax.tools_count Number of tools provided

Available Models

Model Description
MiniMax-M2.7 Latest flagship model with enhanced reasoning and coding
MiniMax-M2.7-highspeed High-speed version of M2.7 for low-latency scenarios
MiniMax-M2.5 General-purpose model with 204K context window
MiniMax-M2.5-highspeed Faster inference variant with 204K context window

Important Notes

  1. OpenAI SDK Required: MiniMax uses the OpenAI-compatible API, so you need the openai package installed.

  2. Base URL: Always set base_url="https://api.minimax.io/v1" when creating the client.

  3. API Key: Get your API key from the MiniMax Platform.

  4. Selective Instrumentation: The instrumentor only traces calls to MiniMax's API. Regular OpenAI API calls are not affected.

  5. Temperature: MiniMax requires temperature to be in the range (0.0, 1.0]. A value of exactly 0 is not accepted.

License

Apache-2.0

Metadata

Release files for traceAI-minimax 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for traceAI-minimax 0.1.0
File Size Uploaded Provenance Actions
traceai_minimax-0.1.0.tar.gz 10.9 kB Without provenance Details for traceai_minimax-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for traceAI-minimax 0.1.0
File Interpreter ABI Platform Actions
traceai_minimax-0.1.0-py3-none-any.whl Python 3 none any Details for traceai_minimax-0.1.0-py3-none-any.whl

Total release size: 23.1 kB

Release files / traceai_minimax-0.1.0.tar.gz

Download URL traceai_minimax-0.1.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8bc959a2ba67c535310ab369a3a5fbc102b851b6372b2743445e428de00f65c2
BLAKE2b-256 checksum
How to use checksums
634435e0d1d8f9455a541df1c678a968cd819771b803a857d69d649226508af0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / traceai_minimax-0.1.0-py3-none-any.whl

Download URL traceai_minimax-0.1.0-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
faa35a9ddbcb04ed0094525d1a12326d8b44b2b8c66049328e39c9dfe4d40938
BLAKE2b-256 checksum
How to use checksums
736d44dec002b9a6574a3b99c6c77addbd11f210ff1f021ac6aea4170bfe6b34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for traceAI-minimax 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page