MiniMax
MiniMax
LiteLLM에서 MiniMax 모델을 사용하는 방법을 알아봐요. Anthropic Messages 호환 및 OpenAI 호환 API 모두를 지원해요.
출처: 문서
본문
MiniMax - v1/messages
개요
LiteLLM은 MiniMax에 대한 anthropic 스펙 호환 지원을 제공해요.
지원 모델
MiniMax는 Anthropic 호환 API를 통해 세 가지 모델을 제공해요:
| 모델 | 설명 | 입력 비용 | 출력 비용 | Prompt Caching Read | Prompt Caching Write |
|---|---|---|---|---|---|
| MiniMax-M2.1 | 강력한 다국어 프로그래밍과 향상된 프로그래밍 경험 (~60 tps) | $0.3/M tokens | $1.2/M tokens | $0.03/M tokens | $0.375/M tokens |
| MiniMax-M2.1-lightning | 더 빠르고 민첩함 (~100 tps) | $0.3/M tokens | $2.4/M tokens | $0.03/M tokens | $0.375/M tokens |
| MiniMax-M2 | 에이전트 능력, 고급 추론 | $0.3/M tokens | $1.2/M tokens | $0.03/M tokens | $0.375/M tokens |
사용 예시
기본 채팅 완성
import litellm
response = litellm.anthropic.messages.acreate(
model="minimax/MiniMax-M2.1",
messages=[{"role": "user", "content": "Hello, how are you?"}],
api_key="your-minimax-api-key",
api_base="https://api.minimax.io/anthropic/v1/messages",
max_tokens=1000
)
print(response.choices[0].message.content)
환경 변수 사용
export MINIMAX_API_KEY="your-minimax-api-key"
export MINIMAX_API_BASE="https://api.minimax.io/anthropic/v1/messages"
import litellm
response = litellm.anthropic.messages.acreate(
model="minimax/MiniMax-M2.1",
messages=[{"role": "user", "content": "Hello!"}],
max_tokens=1000
)
Thinking 기능과 함께 (M2.1 기능)
response = litellm.anthropic.messages.acreate(
model="minimax/MiniMax-M2.1",
messages=[{"role": "user", "content": "Solve: 2+2=?"}],
thinking={"type": "enabled", "budget_tokens": 1000},
api_key="your-minimax-api-key"
)
# Access thinking content
for block in response.choices[0].message.content:
if hasattr(block, 'type') and block.type == 'thinking':
print(f"Thinking: {block.thinking}")
도구 호출과 함께
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}
}
]
response = litellm.anthropic.messages.acreate(
model="minimax/MiniMax-M2.1",
messages=[{"role": "user", "content": "What's the weather in SF?"}],
tools=tools,
api_key="your-minimax-api-key",
max_tokens=1000
)
LiteLLM Proxy와 함께 사용
Anthropic SDK를 통해 LiteLLM Proxy로 라우팅하면 MiniMax 모델을 사용할 수 있어요:
| 단계 | 설명 |
|---|---|
| 1. LiteLLM Proxy 시작 | config.yaml에 MiniMax 모델로 proxy 구성 |
| 2. 환경 변수 설정 | Anthropic SDK를 proxy 엔드포인트로 지정 |
| 3. Anthropic SDK 사용 | 네이티브 Anthropic SDK로 MiniMax 모델 호출 |
1단계: LiteLLM Proxy 구성
config.yaml:
model_list:
- model_name: minimax/MiniMax-M2.1
litellm_params:
model: minimax/MiniMax-M2.1
api_key: os.environ/MINIMAX_API_KEY
api_base: https://api.minimax.io/anthropic/v1/messages
Proxy 시작:
litellm --config config.yaml
2단계: Anthropic SDK로 사용
import os
os.environ["ANTHROPIC_BASE_URL"] = "http://localhost:4000"
os.environ["ANTHROPIC_API_KEY"] = "sk-" # Your LiteLLM proxy key
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="minimax/MiniMax-M2.1",
max_tokens=1000,
system="You are a helpful assistant.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Hi, how are you?"
}
]
}
]
)
for block in message.content:
if block.type == "thinking":
print(f"Thinking:\n{block.thinking}\n")
elif block.type == "text":
print(f"Text:\n{block.text}\n")
MiniMax - v1/chat/completions
LiteLLM SDK로 사용
MiniMax의 OpenAI 호환 API를 LiteLLM으로 직접 사용할 수 있어요.
기본 채팅 완성
import litellm
response = litellm.completion(
model="minimax/MiniMax-M2.1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, how are you?"}
],
api_key="your-minimax-api-key",
api_base="https://api.minimax.io/v1"
)
print(response.choices[0].message.content)
환경 변수 사용
export MINIMAX_API_KEY="your-minimax-api-key"
export MINIMAX_API_BASE="https://api.minimax.io/v1"
import litellm
response = litellm.completion(
model="minimax/MiniMax-M2.1",
messages=[{"role": "user", "content": "Hello!"}]
)
Reasoning Split과 함께
response = litellm.completion(
model="minimax/MiniMax-M2.1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Solve: 2+2=?"}
],
extra_body={"reasoning_split": True},
api_key="your-minimax-api-key",
api_base="https://api.minimax.io/v1"
)
# Access reasoning details if available
if hasattr(response.choices[0].message, 'reasoning_details'):
print(f"Thinking: {response.choices[0].message.reasoning_details}")
print(f"Response: {response.choices[0].message.content}")
도구 호출과 함께
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}
}
]
response = litellm.completion(
model="minimax/MiniMax-M2.1",
messages=[{"role": "user", "content": "What's the weather in SF?"}],
tools=tools,
api_key="your-minimax-api-key",
api_base="https://api.minimax.io/v1"
)
스트리밍
response = litellm.completion(
model="minimax/MiniMax-M2.1",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
api_key="your-minimax-api-key",
api_base="https://api.minimax.io/v1"
)
for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
LiteLLM Proxy를 통한 OpenAI SDK 사용
1단계: LiteLLM Proxy 구성
config.yaml:
model_list:
- model_name: minimax/MiniMax-M2.1
litellm_params:
model: minimax/MiniMax-M2.1
api_key: os.environ/MINIMAX_API_KEY
api_base: https://api.minimax.io/v1
Proxy 시작:
litellm --config config.yaml
2단계: OpenAI SDK로 사용
import os
os.environ["OPENAI_BASE_URL"] = "http://localhost:4000"
os.environ["OPENAI_API_KEY"] = "sk-" # Your LiteLLM proxy key
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="minimax/MiniMax-M2.1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hi, how are you?"},
],
# Set reasoning_split=True to separate thinking content
extra_body={"reasoning_split": True},
)
# Access thinking and response
if hasattr(response.choices[0].message, 'reasoning_details'):
print(f"Thinking:\n{response.choices[0].message.reasoning_details[0]['text']}\n")
print(f"Text:\n{response.choices[0].message.content}\n")
OpenAI SDK 스트리밍
from openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model="minimax/MiniMax-M2.1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me a story"},
],
extra_body={"reasoning_split": True},
stream=True,
)
reasoning_buffer = ""
text_buffer = ""
for chunk in stream:
if hasattr(chunk.choices[0].delta, "reasoning_details") and chunk.choices[0].delta.reasoning_details:
for detail in chunk.choices[0].delta.reasoning_details:
if "text" in detail:
reasoning_text = detail["text"]
new_reasoning = reasoning_text[len(reasoning_buffer):]
if new_reasoning:
print(new_reasoning, end="", flush=True)
reasoning_buffer = reasoning_text
if chunk.choices[0].delta.content:
content_text = chunk.choices[0].delta.content
new_text = content_text[len(text_buffer):] if text_buffer else content_text
if new_text:
print(new_text, end="", flush=True)
text_buffer = content_text
비용 계산
비용 계산은 model_prices_and_context_window.json의 가격 정보를 사용해 자동으로 동작해요.
response = litellm.completion(
model="minimax/MiniMax-M2.1",
messages=[{"role": "user", "content": "Hello!"}],
api_key="your-minimax-api-key"
)
# Access cost information
print(f"Cost: ${response._hidden_params.get('response_cost', 0)}")
MiniMax - 텍스트 음성 변환 (Text-to-Speech)
빠른 시작
기본 사용법
from pathlib import Path
from litellm import speech
import os
os.environ["MINIMAX_API_KEY"] = "your-api-key"
speech_file_path = Path(__file__).parent / "speech.mp3"
response = speech(
model="minimax/speech-2.6-hd",
voice="alloy",
input="The quick brown fox jumped over the lazy dogs",
)
response.stream_to_file(speech_file_path)
비동기 사용법
from litellm import aspeech
from pathlib import Path
import os, asyncio
os.environ["MINIMAX_API_KEY"] = "your-api-key"
async def test_async_speech():
speech_file_path = Path(__file__).parent / "speech.mp3"
response = await aspeech(
model="minimax/speech-2.6-hd",
voice="alloy",
input="The quick brown fox jumped over the lazy dogs",
)
response.stream_to_file(speech_file_path)
asyncio.run(test_async_speech())
음성 선택
MiniMax는 많은 음성을 지원해요. LiteLLM은 MiniMax 음성에 매핑되는 OpenAI 호환 음성 이름을 제공해요:
from litellm import speech
# OpenAI-compatible voice names
voices = ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
for voice in voices:
response = speech(
model="minimax/speech-2.6-hd",
voice=voice,
input=f"This is the {voice} voice",
)
response.stream_to_file(f"speech_{voice}.mp3")
MiniMax 네이티브 음성 ID를 직접 사용할 수도 있어요:
response = speech(
model="minimax/speech-2.6-hd",
voice="male-qn-qingse", # MiniMax native voice ID
input="Using native MiniMax voice ID",
)
사용자 정의 파라미터
MiniMax TTS는 오디오 출력을 미세 조정하기 위한 추가 파라미터를 지원해요:
from litellm import speech
response = speech(
model="minimax/speech-2.6-hd",
voice="alloy",
input="Custom audio parameters",
speed=1.5, # Speed: 0.5 to 2.0
response_format="mp3", # Format: mp3, pcm, wav, flac
extra_body={
"vol": 1.2, # Volume: 0.1 to 10
"pitch": 2, # Pitch adjustment: -12 to 12
"sample_rate": 32000, # 16000, 24000, or 32000
"bitrate": 128000, # For MP3: 64000, 128000, 192000, 256000
"channel": 1, # 1 for mono, 2 for stereo
}
)
response.stream_to_file("custom_speech.mp3")
응답 형식
from litellm import speech
# MP3 format (default)
response = speech(
model="minimax/speech-2.6-hd",
voice="alloy",
input="MP3 format audio",
response_format="mp3",
)
# PCM format
response = speech(
model="minimax/speech-2.6-hd",
voice="alloy",
input="PCM format audio",
response_format="pcm",
)
# WAV format
response = speech(
model="minimax/speech-2.6-hd",
voice="alloy",
input="WAV format audio",
response_format="wav",
)
# FLAC format
response = speech(
model="minimax/speech-2.6-hd",
voice="alloy",
input="FLAC format audio",
response_format="flac",
)
LiteLLM Proxy 사용법
LiteLLM은 MiniMax TTS용 OpenAI 호환 /audio/speech 엔드포인트를 제공해요.
설정
model_list:
- model_name: tts
litellm_params:
model: minimax/speech-2.6-hd
api_key: os.environ/MINIMAX_API_KEY
- model_name: tts-turbo
litellm_params:
model: minimax/speech-2.6-turbo
api_key: os.environ/MINIMAX_API_KEY
Proxy 시작:
litellm --config /path/to/config.yaml
# RUNNING on http://0.0.0.0:4000
요청하기
curl http://0.0.0.0:4000/v1/audio/speech \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "tts",
"input": "The quick brown fox jumped over the lazy dog.",
"voice": "alloy"
}' \
--output speech.mp3
사용자 정의 파라미터 포함:
curl http://0.0.0.0:4000/v1/audio/speech \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "tts",
"input": "Custom parameters example.",
"voice": "nova",
"speed": 1.5,
"response_format": "mp3",
"extra_body": {
"vol": 1.2,
"pitch": 1,
"sample_rate": 32000
}
}' \
--output custom_speech.mp3
음성 매핑
LiteLLM은 OpenAI 호환 음성 이름을 MiniMax 음성 ID로 매핑해요:
| OpenAI 음성 | MiniMax 음성 ID | 설명 |
|---|---|---|
| alloy | male-qn-qingse | 남성 음성 |
| echo | male-qn-jingying | 남성 음성 |
| fable | female-shaonv | 여성 음성 |
| onyx | male-qn-badao | 남성 음성 |
| nova | female-yujie | 여성 음성 |
| shimmer | female-tianmei | 여성 음성 |
voice 파라미터로 어떤 MiniMax 네이티브 음성 ID든 직접 사용할 수도 있어요.
스트리밍 (WebSocket)
note: 현재 구현은 MiniMax의 HTTP 엔드포인트를 사용해요. WebSocket 스트리밍 지원은 MiniMax 공식 문서(https://platform.minimax.io/docs)를 참고해요.
오류 처리
from litellm import speech
import litellm
try:
response = speech(
model="minimax/speech-2.6-hd",
voice="alloy",
input="Test input",
)
response.stream_to_file("output.mp3")
except litellm.exceptions.BadRequestError as e:
print(f"Bad request: {e}")
except litellm.exceptions.AuthenticationError as e:
print(f"Authentication failed: {e}")
except Exception as e:
print(f"Error: {e}")
Extra Body 파라미터
extra_body로 전달해요:
| 파라미터 | 타입 | 설명 | 기본값 |
|---|---|---|---|
| vol | float | 볼륨 (0.1 ~ 10) | 1.0 |
| pitch | int | 피치 조정 (-12 ~ 12) | 0 |
| sample_rate | int | 샘플 레이트: 16000, 24000, 32000 | 32000 |
| bitrate | int | MP3 비트레이트: 64000, 128000, 192000, 256000 | 128000 |
| channel | int | 오디오 채널: 1 (모노) 또는 2 (스테레오) | 1 |
| output_format | string | 출력 형식: "hex" 또는 "url" (url은 24시간 유효한 URL 반환) | hex |
더 알아보기 (Learn more)
- MiniMax 공식 문서
- LiteLLM TTS API