OpenAI 호환 엔드포인트 시도해 보기

OpenAI 호환 엔드포인트 시도해 보기

LocalAI를 설치했다면, 실행 중인 서버에서 각 OpenAI 호환 엔드포인트를 curl로 바로 시험해 볼 수 있어요. 기본적으로 웹 UI는 http://localhost:8080에서 접근할 수 있어요. 이 문서는 채팅·비전·함수 호출·이미지·TTS·STT·임베딩 예제를 제공해요. 각 예제는 이름이 붙은 모델을 이미 설치했다고 가정해요(예: 채팅·함수는 qwen3-4b).

텍스트 생성(채팅)

curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{ "model": "qwen3-4b", "messages": [{"role": "user", "content": "How are you doing?"}] }'

출처: https://localai.io/docs/basics/try/

GPT 비전

이미지를 이해시키려면 image_url 형태의 콘텐츠를 넣어요.

curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4-vision-preview",
    "messages": [{"role": "user", "content": [
        {"type":"text", "text":"What is in the image?"},
        {"type":"image_url", "image_url":{"url":"<image_url>"}}
    ]}]
  }'

함수 호출

OpenAI 호환 tools 형식으로 함수를 정의하고 tool_choice: "auto"를 쓰면 돼요.

curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3-4b",
    "messages": [{"role": "user", "content": "What is the weather like in Boston?"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_current_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {"type": "string", "description": "The city and state"},
            "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
          },
          "required": ["location"]
        }
      }
    }],
    "tool_choice": "auto"
  }'

이미지 생성

curl http://localhost:8080/v1/images/generations \
  -H "Content-Type: application/json" -d '{
    "prompt": "A cute baby sea otter",
    "size": "256x256"
  }'

텍스트→음성

curl http://localhost:8080/v1/audio/speech \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1",
    "input": "The quick brown fox jumped over the lazy dog.",
    "voice": "alloy"
  }' \
  --output speech.mp3

음성→텍스트(STT)

curl http://localhost:8080/v1/audio/transcriptions \
  -H "Content-Type: multipart/form-data" \
  -F file="@$PWD/gb1.ogg" -F model="whisper-1"

임베딩

curl http://localhost:8080/embeddings \
  -X POST -H "Content-Type: application/json" \
  -d '{ "input": "Your text string goes here", "model": "text-embedding-ada-002" }'

Anthropic·Open Responses API

LocalAI는 Anthropic 클로드 호환 모델을 위한 /v1/messages API와, 백그라운드 처리·스트리밍을 지원하는 Open Responses API(/v1/responses)도 지원해요. 요청에 "anthropic-version: 2023-06-01" 헤더를 넣으면 Anthropic 형식으로 쓸 수 있어요.

  • 모델 파일명을 model로 쓰지 말고, 설치된 모델의 이름(예: qwen3-4b)을 써요.
  • 요청의 model은 설치한 모델의 이름과 일치해야 해요.

더 알아보기