Mistral

Mistral

Mistral의 패스스루 엔드포인트를 소개할게요. Mistral의 프로바이더 고유 엔드포인트를 네이티브 형식 그대로(변환 없이) 호출할 수 있는 기능이에요. OCR 같은 Mistral 전용 API도 그대로 사용할 수 있어요.

출처: 문서

본문

연결 대상 호스트는 https://api.mistral.ai/v1이고, 프록시를 통한 주소는 이렇게 구성돼요.

LITELLM_PROXY_BASE_URL/mistral

사용 예시 (Example Usage)

Mistral의 /v1/ocr 엔드포인트를 호출하는 예시예요.

curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/ocr' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
-d '{
    "model": "mistral-ocr-latest",
    "document": {
        "type": "image_url",
        "image_url": "https://raw.githubusercontent.com/mistralai/cookbook/refs/heads/main/mistral/ocr/receipt.png"
    }
}'

빠른 시작 (Quick Start)

Mistral의 /chat/completions 엔드포인트를 호출하는 예시예요. 먼저 API 키를 환경 변수로 설정해요.

export MISTRAL_API_KEY="sk-<your-litellm-api-key>"

그다음 LiteLLM 프록시를 실행해요.

litellm
# RUNNING on http://0.0.0.0:4000

이제 /ocr 엔드포인트를 호출해요.

curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/ocr' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
-d '{
    "model": "mistral-ocr-latest",
    "document": {
        "type": "image_url",
        "image_url": "https://raw.githubusercontent.com/mistralai/cookbook/refs/heads/main/mistral/ocr/receipt.png"
    }
}'

예시 (Examples)

핵심 아이디어는 단순해요. Mistral SDK/API의 호스트를 http://0.0.0.0:4000/mistral로 바꾸면 돼요. 원래 https://api.mistral.ai/v1을 호출하던 것을 http://0.0.0.0:4000/mistral로 바꾸고, 인증 헤더를 bearer $MISTRAL_API_KEY 대신 LiteLLM 키(bearer anything 또는 가상 키 bearer LITELLM_VIRTUAL_KEY)로 바꾸면 됩니다.

예시 1: OCR 엔드포인트

LiteLLM 프록시 호출

curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/ocr' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
-d '{
    "model": "mistral-ocr-latest",
    "document": {
        "type": "image_url",
        "image_url": "https://raw.githubusercontent.com/mistralai/cookbook/refs/heads/main/mistral/ocr/receipt.png"
    }
}'

Mistral 직접 API 호출 (변환 전)

curl https://api.mistral.ai/v1/ocr \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${MIST...KEY}" \
  -d '{
    "model": "mistral-ocr-latest",
    "document": {
        "type": "document_url",
        "document_url": "https://arxiv.org/pdf/2201.04234"
    },
    "include_image_base64": true
  }'

예시 2: chat API

LiteLLM 프록시 호출

curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer $LITEL..._KEY' \
-d '{
    "messages": [
        {
            "role": "user",
            "content": "I am going to Paris, what should I see?"
        }
    ],
    "max_tokens": 2048,
    "temperature": 0.8,
    "top_p": 0.1,
    "model": "mistral-large-latest",
}'

Mistral 직접 API 호출 (변환 전)

curl -L -X POST 'https://api.mistral.ai/v1/chat/completions' \
-H 'Content-Type: application/json' \
-d '{
    "messages": [
        {
            "role": "user",
            "content": "I am going to Paris, what should I see?"
        }
    ],
    "max_tokens": 2048,
    "temperature": 0.8,
    "top_p": 0.1,
    "model": "mistral-large-latest",
}'

고급: 가상 키(Virtual Keys)와 함께 사용하기

가상 키는 LiteLLM 프록시에 데이터베이스가 설정된 경우에 사용할 수 있어요. 가상 키 설정 문서를 참고해 주세요.

사용법 (Usage)

환경 변수를 설정해요.

export DATABASE_URL=""
export LITELLM_MASTER_KEY=""
export MISTRAL_API_BASE=""

프록시를 실행해요.

litellm
# RUNNING on http://0.0.0.0:4000

가상 키를 생성해요.

curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H "Authorization: Bearer ***" \
-H 'Content-Type: application/json' \
-d '{}'

응답에서 키를 받아요.

{
    ...
    "key": "sk-<virtual-key>"
}

이제 chat completions 엔드포인트를 가상 키로 호출해요.

curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
  --data '{
    "messages": [
        {
            "role": "user",
            "content": "I am going to Paris, what should I see?"
        }
    ],
    "max_tokens": 2048,
    "temperature": 0.8,
    "top_p": 0.1,
    "model": "qwen2.5-7b-instruct",
}'

더 알아보기 (Learn more)