/containers
/containers
격리된 환경에서 코드를 실행하기 위한 OpenAI 코드 인터프리터 컨테이너(세션)를 관리해요.
Code Interpreter 사용법이 궁금하다면 Code Interpreter Guide 를 참고하세요.
| 기능 | 지원 |
|---|---|
| 비용 추적 (Cost Tracking) | ✅ |
| 로깅 (Logging) | ✅ (전체 요청/응답 로깅) |
| 로드 밸런싱 (Load Balancing) | ✅ |
| Proxy Server 지원 | ✅ 가상 키와 함께하는 전체 프록시 통합 |
| 지출 관리 (Spend Management) | ✅ 예산 추적 및 속도 제한 |
| 지원 프로바이더 | openai |
컨테이너는 코드 인터프리터 세션을 위한 격리된 실행 환경을 제공합니다. 컨테이너를 생성, 나열, 조회, 삭제할 수 있어요.
LiteLLM Python SDK 사용법
빠른 시작
컨테이너 생성:
import litellm
import os
# setup env
os.environ["OPENAI_API_KEY"] = "sk-.."
container = litellm.create_container(
name="My Code Interpreter Container",
custom_llm_provider="openai",
expires_after={
"anchor": "last_active_at",
"minutes": 20
}
)
print(f"Container ID: {container.id}")
print(f"Container Name: {container.name}")
Async 사용법
from litellm import acreate_container
import os
os.environ["OPENAI_API_KEY"] = "sk-.."
container = await acreate_container(
name="My Code Interpreter Container",
custom_llm_provider="openai",
expires_after={
"anchor": "last_active_at",
"minutes": 20
}
)
print(f"Container ID: {container.id}")
print(f"Container Name: {container.name}")
컨테이너 나열
from litellm import list_containers
import os
os.environ["OPENAI_API_KEY"] = "sk-.."
containers = list_containers(
custom_llm_provider="openai",
limit=20,
order="desc"
)
print(f"Found {len(containers.data)} containers")
for container in containers.data:
print(f" - {container.id}: {container.name}")
Async 사용법:
from litellm import alist_containers
containers = await alist_containers(
custom_llm_provider="openai",
limit=20,
order="desc"
)
print(f"Found {len(containers.data)} containers")
for container in containers.data:
print(f" - {container.id}: {container.name}")
컨테이너 조회
from litellm import retrieve_container
import os
os.environ["OPENAI_API_KEY"] = "sk-.."
container = retrieve_container(
container_id="cntr_123...",
custom_llm_provider="openai"
)
print(f"Container: {container.name}")
print(f"Status: {container.status}")
print(f"Created: {container.created_at}")
Async 사용법:
from litellm import aretrieve_container
container = await aretrieve_container(
container_id="cntr_123...",
custom_llm_provider="openai"
)
print(f"Container: {container.name}")
print(f"Status: {container.status}")
print(f"Created: {container.created_at}")
컨테이너 삭제
from litellm import delete_container
import os
os.environ["OPENAI_API_KEY"] = "sk-.."
result = delete_container(
container_id="cntr_123...",
custom_llm_provider="openai"
)
print(f"Deleted: {result.deleted}")
print(f"Container ID: {result.id}")
Async 사용법:
from litellm import adelete_container
result = await adelete_container(
container_id="cntr_123...",
custom_llm_provider="openai"
)
print(f"Deleted: {result.deleted}")
print(f"Container ID: {result.id}")
출처: 문서
본문
LiteLLM Proxy 사용법
LiteLLM은 코드 인터프리터 세션 관리를 위한 OpenAI API 호환 컨테이너 엔드포인트를 제공합니다:
/v1/containers- 컨테이너 생성 및 나열/v1/containers/{container_id}- 컨테이너 조회 및 삭제
설정:
$ export OPENAI_API_KEY="sk-..."
$ litellm
# RUNNING on http://0.0.0.0:4000
OpenAI 키는 환경 대신 model_list 에 있을 수도 있어요. 생성 본문에서 그 배포의 모델을 전달하거나 목록의 model query param으로 전달하면, 프록시는 배포의 api_key 와 api_base 로 OpenAI를 호출합니다. 조회, 삭제, 컨테이너 파일 호출은 모델이 필요 없어요: 라우팅된 생성이 반환한 ID가 배포를 인코딩하므로 스스로 라우팅됩니다.
model_list:
- model_name: gpt-5.6
litellm_params:
model: openai/gpt-5.6
api_key: os.environ/OPENAI_API_KEY_TEAM_A
$ litellm --config config.yaml
커스텀 프로바이더 지정 — 커스텀 LLM 프로바이더를 여러 방법으로 지정할 수 있어요 (우선순위 순서):
- 헤더:
-H "custom-llm-provider: openai" - Query param:
?custom_llm_provider=openai - 요청 본문:
{"custom_llm_provider": "openai", ...} - 지정하지 않으면 기본
"openai"
컨테이너 생성:
# Default provider (openai)
curl -X POST "http://localhost:4000/v1/containers" \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"name": "My Container",
"expires_after": {
"anchor": "last_active_at",
"minutes": 20
}
}'
# Via header
curl -X POST "http://localhost:4000/v1/containers" \
-H "Authorization: Bearer ***" \
-H "custom-llm-provider: openai" \
-H "Content-Type: application/json" \
-d '{
"name": "My Container"
}'
# Via query parameter
curl -X POST "http://localhost:4000/v1/containers?custom_llm_provider=openai" \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"name": "My Container"
}'
# With model_list credentials: name the deployment
curl -X POST "http://localhost:4000/v1/containers" \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"name": "My Container",
"model": "gpt-5.6"
}'
컨테이너 나열:
curl "http://localhost:4000/v1/containers?limit=20&order=desc" \
-H "Authorization: Bearer ***"
# With model_list credentials: name the deployment
curl "http://localhost:4000/v1/containers?model=gpt-5.6&limit=20&order=desc" \
-H "Authorization: Bearer ***"
컨테이너 조회:
curl "http://localhost:4000/v1/containers/cntr_123..." \
-H "Authorization: Bearer ***"
컨테이너 삭제:
curl -X DELETE "http://localhost:4000/v1/containers/cntr_123..." \
-H "Authorization: Bearer ***"
LiteLLM Proxy와 함께 OpenAI 클라이언트 사용
표준 OpenAI Python 클라이언트를 사용해 LiteLLM의 컨테이너 엔드포인트와 상호작용할 수 있어요. LiteLLM의 프록시 기능을 유지하면서 익숙한 인터페이스를 제공합니다.
설정
먼저 OpenAI 클라이언트가 LiteLLM 프록시를 가리키도록 구성하세요:
from openai import OpenAI
client = OpenAI(
api_key="sk-<your-litellm-api-key>", # Your LiteLLM proxy key
base_url="http://localhost:4000" # LiteLLM proxy URL
)
컨테이너 생성
container = client.containers.create(
name="test-container",
expires_after={
"anchor": "last_active_at",
"minutes": 20
},
extra_body={"custom_llm_provider": "openai"}
)
print(f"Container ID: {container.id}")
print(f"Container Name: {container.name}")
print(f"Created at: {container.created_at}")
model_list 자격 증명을 쓸 때는 extra_body 에 배포를 명명하세요:
container = client.containers.create(
name="test-container",
extra_body={"model": "gpt-5.6"}
)
컨테이너 나열
containers = client.containers.list(
limit=20,
extra_body={"custom_llm_provider": "openai"}
)
print(f"Found {len(containers.data)} containers")
for container in containers.data:
print(f" - {container.id}: {container.name}")
model_list 자격 증명을 쓸 때는 목록이 GET이므로 extra_query 에 배포를 명명하세요:
containers = client.containers.list(
limit=20,
extra_query={"model": "gpt-5.6"}
)
컨테이너 조회
container = client.containers.retrieve(
container_id="cntr_6901d28b3c8881908b702815828a5bde0380b3408aeae8c7",
extra_body={"custom_llm_provider": "openai"}
)
print(f"Container: {container.name}")
print(f"Status: {container.status}")
print(f"Last active: {container.last_active_at}")
컨테이너 삭제
result = client.containers.delete(
container_id="cntr_6901d28b3c8881908b702815828a5bde0380b3408aeae8c7",
extra_body={"custom_llm_provider": "openai"}
)
print(f"Deleted: {result.deleted}")
print(f"Container ID: {result.id}")
완전한 워크플로 예시
다음은 완전한 컨테이너 관리 워크플로를 보여주는 예시입니다:
from openai import OpenAI
# Initialize client
client = OpenAI(
api_key="sk-<your-litellm-api-key>",
base_url="http://localhost:4000"
)
# 1. Create a container
print("Creating container...")
container = client.containers.create(
name="My Code Interpreter Session",
expires_after={
"anchor": "last_active_at",
"minutes": 20
},
extra_body={"custom_llm_provider": "openai"}
)
container_id = container.id
print(f"Container created. ID: {container_id}")
# 2. List all containers
print("\nListing containers...")
containers = client.containers.list(
extra_body={"custom_llm_provider": "openai"}
)
for c in containers.data:
print(f" - {c.id}: {c.name} (Status: {c.status})")
# 3. Retrieve specific container
print(f"\nRetrieving container {container_id}...")
retrieved = client.containers.retrieve(
container_id=container_id,
extra_body={"custom_llm_provider": "openai"}
)
print(f"Container: {retrieved.name}")
print(f"Status: {retrieved.status}")
print(f"Last active: {retrieved.last_active_at}")
# 4. Delete container
print(f"\nDeleting container {container_id}...")
result = client.containers.delete(
container_id=container_id,
extra_body={"custom_llm_provider": "openai"}
)
print(f"Deleted: {result.deleted}")
컨테이너 파라미터
컨테이너 생성 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
name |
string | 예 | 컨테이너 이름 |
expires_after |
object | 아니요 | 컨테이너 만료 설정 |
expires_after.anchor |
string | 아니요 | 만료 앵커 포인트 (예: "last_active_at") |
expires_after.minutes |
integer | 아니요 | 앵커로부터 만료까지의 분 |
file_ids |
array | 아니요 | 컨테이너에 포함할 파일 ID 목록 |
custom_llm_provider |
string | 아니요 | 사용할 LLM 프로바이더 (기본: "openai") |
컨테이너 나열 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
after |
string | 아니요 | 페이지네이션 커서 |
limit |
integer | 아니요 | 반환할 항목 수 (1-100, 기본: 20) |
order |
string | 아니요 | 정렬 순서: "asc" 또는 "desc" (기본: "desc") |
custom_llm_provider |
string | 아니요 | 사용할 LLM 프로바이더 (기본: "openai") |
컨테이너 조회/삭제 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
container_id |
string | 예 | 조회/삭제할 컨테이너 ID |
custom_llm_provider |
string | 아니요 | 사용할 LLM 프로바이더 (기본: "openai") |
응답 객체
ContainerObject
{
"id": "cntr_123...",
"object": "container",
"created_at": 1234567890,
"name": "My Container",
"status": "active",
"last_active_at": 1234567890,
"expires_at": 1234569090,
"file_ids": []
}
ContainerListResponse
{
"object": "list",
"data": [
{
"id": "cntr_123...",
"object": "container",
"created_at": 1234567890,
"name": "My Container",
"status": "active"
}
],
"first_id": "cntr_123...",
"last_id": "cntr_456...",
"has_more": false
}
DeleteContainerResult
{
"id": "cntr_123...",
"object": "container.deleted",
"deleted": true
}
지원 프로바이더
| 프로바이더 | 지원 상태 | 비고 |
|---|---|---|
| OpenAI | ✅ 지원 | 모든 컨테이너 작업에 대한 전체 지원 |
현재 코드 인터프리터 세션용 컨테이너 관리를 지원하는 것은 OpenAI뿐입니다. 추가 프로바이더 지원은 향후 추가될 수 있어요.
더 알아보기 (Learn more)
- Container Files API - 컨테이너 내 파일 관리
- Code Interpreter Guide - LiteLLM으로 Code Interpreter 사용하기