/interactions 엔드포인트

/interactions 엔드포인트

Interactions API를 통한 상호작용 생성 방법을 알려드릴게요. Google AI Studio 네이티브 지원과, 다른 프로바이더를 /responses 브리지로 호출하는 방법까지 다뤄요.

출처: 문서

본문

기능 지원 비고
로깅 (Logging) 모든 통합에서 작동
스트리밍
로드밸런싱 지원 모델 간
지원 LLM 프로바이더 모든 LiteLLM 지원 CHAT COMPLETION 프로바이더 openai, anthropic, bedrock, vertex_ai, gemini, azure, azure_ai

LiteLLM Python SDK 사용법

퀵 스타트

import litellm
import os

os.environ["GEMINI_API_KEY"] = "your-api-key"

response = litellm.interactions.create(
    model="gemini/gemini-3.8-flash",
    input="Tell me a short joke about programming."
)
print(response.outputs[-1].text)

비동기 사용법

import litellm
import os
import asyncio

os.environ["GEMINI_API_KEY"] = "your-api-key"

async def main():
    response = await litellm.interactions.acreate(
        model="gemini/gemini-3.8-flash",
        input="Tell me a short joke about programming."
    )
    print(response.outputs[-1].text)

asyncio.run(main())

스트리밍

import litellm
import os

os.environ["GEMINI_API_KEY"] = "your-api-key"

response = litellm.interactions.create(
    model="gemini/gemini-3.8-flash",
    input="Write a 3 paragraph story about a robot.",
    stream=True
)
for chunk in response:
    print(chunk)

LiteLLM AI Gateway (Proxy) 사용법

설정

litellm proxy config.yaml에 추가하세요:

model_list:
  - model_name: gemini-flash
    litellm_params:
      model: gemini/gemini-3.8-flash
      api_key: os.environ/GEMINI_API_KEY

litellm 시작:

litellm --config /path/to/config.yaml
# RUNNING on http://0.0.0.0:4000

테스트 요청

curl:

curl -X POST "http://localhost:4000/v1beta/interactions" \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini/gemini-3.8-flash",
    "input": "Tell me a short joke about programming."
  }'

스트리밍:

curl -N -X POST "http://localhost:4000/v1beta/interactions" \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini/gemini-3.8-flash",
    "input": "Write a 3 paragraph story about a robot.",
    "stream": true
  }'

상호작용 가져오기(ID로):

curl "http://localhost:4000/v1beta/interactions/{interaction_id}" \
  -H "Authorization: Bearer ***"

Google GenAI SDK를 LiteLLM Proxy에 연결:

from google import genai

# Point SDK to LiteLLM Proxy
client = genai.Client(
    api_key="sk-<your-litellm-api-key>",  # Your LiteLLM API key
    http_options={
        "base_url": "http://localhost:4000"
    },
)

# Create an interaction
interaction = client.interactions.create(
    model="gemini/gemini-3.8-flash",
    input="Tell me a short joke about programming."
)
print(interaction.outputs[-1].text)

스트리밍:

from google import genai

client = genai.Client(
    api_key="sk-<your-litellm-api-key>",  # Your LiteLLM API key
    http_options={
        "base_url": "http://localhost:4000"
    },
)

for chunk in client.interactions.create_stream(
    model="gemini/gemini-3.8-flash",
    input="Write a story about space exploration.",
):
    print(chunk)

요청/응답 형식 (Request/Response Format)

요청 파라미터

파라미터 타입 필수 설명
model string 사용할 모델 (예: gemini/gemini-2.5-flash)
input string 상호작용 입력 텍스트
stream boolean 아니요 스트리밍 응답 활성화
tools array 아니요 모델에 제공할 도구
system_instruction string 아니요 모델용 시스템 지시문
generation_config object 아니요 생성 설정
previous_interaction_id string 아니요 컨텍스트용 이전 상호작용 ID

응답 형식

{
  "id": "interaction_abc123",
  "object": "interaction",
  "model": "gemini-3.8-flash",
  "status": "completed",
  "created": "2025-01-15T10:30:00Z",
  "updated": "2025-01-15T10:30:05Z",
  "role": "model",
  "outputs": [
    {
      "type": "text",
      "text": "Why do programmers prefer dark mode? Because light attracts bugs!"
    }
  ],
  "usage": {
    "total_input_tokens": 10,
    "total_output_tokens": 15,
    "total_tokens": 25
  }
}

Interactions가 아닌 API 엔드포인트 호출하기 (/interactions → /responses 브리지)

LiteLLM은 Interactions API를 네이티브로 지원하지 않는 OpenAI, Anthropic 등 프로바이더를 위해, /interactions를 LiteLLM의 /responses 엔드포인트로 브리징해서 호출할 수 있어요.

Python SDK 사용법

import litellm
import os

# Set API key
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"

# Non-streaming interaction
response = litellm.interactions.create(
    model="gpt-5.6-terra",
    input="Tell me a short joke about programming."
)
print(response.outputs[-1].text)

LiteLLM Proxy 사용법

설정 예시:

model_list:
- model_name: openai-model
  litellm_params:
    model: gpt-5.6-terra
    api_key: os.environ/OPENAI_API_KEY

프록시 시작:

litellm --config /path/to/config.yaml
# RUNNING on http://0.0.0.0:4000

요청:

curl http://localhost:4000/v1beta/interactions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ***" \
  -d '{
    "model": "openai-model",
    "input": "Tell me a short joke about programming."
  }'

지원 프로바이더 (Supported Providers)

프로바이더 사용법 링크
Google AI Studio Usage
기타 모든 LiteLLM 프로바이더 Bridge Usage

더 알아보기 (Learn more)