Together AI
Together AI
LiteLLM에서 Together AI의 모든 모델을 사용하는 방법을 알아봐요.
출처: 문서
본문
LiteLLM은 Together AI의 모든 모델을 지원해요.
API 키
import os
os.environ["TOGETHERAI_API_KEY"] = "your-api-key"
사용 예시
from litellm import completion
os.environ["TOGETHERAI_API_KEY"] = "your-api-key"
messages = [{"role": "user", "content": "Write me a poem about the blue sky"}]
completion(model="together_ai/togethercomputer/Llama-2-7B-32K-Instruct", messages=messages)
Together AI 모델
liteLLM은 https://api.together.xyz/ 의 모든 모델에 대한 non-streaming 및 streaming 요청을 지원해요.
참고: liteLLM은 TogetherAI에 배포된 모든 모델을 지원해요.
Llama LLMs - 채팅
| 모델명 | 함수 호출 | 필요 OS 변수 |
|---|---|---|
| togethercomputer/llama-2-70b-chat | completion('together_ai/togethercomputer/llama-2-70b-chat', messages) |
os.environ['TOGETHERAI_API_KEY'] |
Llama LLMs - 언어 / Instruct
| 모델명 | 함수 호출 | 필요 OS 변수 |
|---|---|---|
| togethercomputer/llama-2-70b | completion('together_ai/togethercomputer/llama-2-70b', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| togethercomputer/LLaMA-2-7B-32K | completion('together_ai/togethercomputer/LLaMA-2-7B-32K', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| togethercomputer/Llama-2-7B-32K-Instruct | completion('together_ai/togethercomputer/Llama-2-7B-32K-Instruct', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| togethercomputer/llama-2-7b | completion('together_ai/togethercomputer/llama-2-7b', messages) |
os.environ['TOGETHERAI_API_KEY'] |
Falcon LLMs
| 모델명 | 함수 호출 | 필요 OS 변수 |
|---|---|---|
| togethercomputer/falcon-40b-instruct | completion('together_ai/togethercomputer/falcon-40b-instruct', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| togethercomputer/falcon-7b-instruct | completion('together_ai/togethercomputer/falcon-7b-instruct', messages) |
os.environ['TOGETHERAI_API_KEY'] |
Alpaca LLMs
| 모델명 | 함수 호출 | 필요 OS 변수 |
|---|---|---|
| togethercomputer/alpaca-7b | completion('together_ai/togethercomputer/alpaca-7b', messages) |
os.environ['TOGETHERAI_API_KEY'] |
기타 채팅 LLMs
| 모델명 | 함수 호출 | 필요 OS 변수 |
|---|---|---|
| HuggingFaceH4/starchat-alpha | completion('together_ai/HuggingFaceH4/starchat-alpha', messages) |
os.environ['TOGETHERAI_API_KEY'] |
코드 LLMs
| 모델명 | 함수 호출 | 필요 OS 변수 |
|---|---|---|
| togethercomputer/CodeLlama-34b | completion('together_ai/togethercomputer/CodeLlama-34b', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| togethercomputer/CodeLlama-34b-Instruct | completion('together_ai/togethercomputer/CodeLlama-34b-Instruct', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| togethercomputer/CodeLlama-34b-Python | completion('together_ai/togethercomputer/CodeLlama-34b-Python', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| defog/sqlcoder | completion('together_ai/defog/sqlcoder', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| NumbersStation/nsql-llama-2-7B | completion('together_ai/NumbersStation/nsql-llama-2-7B', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| WizardLM/WizardCoder-15B-V1.0 | completion('together_ai/WizardLM/WizardCoder-15B-V1.0', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| WizardLM/WizardCoder-Python-34B-V1.0 | completion('together_ai/WizardLM/WizardCoder-Python-34B-V1.0', messages) |
os.environ['TOGETHERAI_API_KEY'] |
언어 LLMs
| 모델명 | 함수 호출 | 필요 OS 변수 |
|---|---|---|
| NousResearch/Nous-Hermes-Llama2-13b | completion('together_ai/NousResearch/Nous-Hermes-Llama2-13b', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| Austism/chronos-hermes-13b | completion('together_ai/Austism/chronos-hermes-13b', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| upstage/SOLAR-0-70b-16bit | completion('together_ai/upstage/SOLAR-0-70b-16bit', messages) |
os.environ['TOGETHERAI_API_KEY'] |
| WizardLM/WizardLM-70B-V1.0 | completion('together_ai/WizardLM/WizardLM-70B-V1.0', messages) |
os.environ['TOGETHERAI_API_KEY'] |
프롬프트 템플릿
Together AI의 자체 프롬프트 형식이 있는 채팅 모델을 사용하시나요?
Llama2 Instruct 모델 사용
Together AI의 Llama2 변형(model=togethercomputer/llama-2..-instruct)을 사용한다면, LiteLLM이 OpenAI 프롬프트 형식과 TogetherAI Llama2 형식([INST]..[/INST]) 사이를 자동으로 변환할 수 있어요.
from litellm import completion
# set env variable
os.environ["TOGETHERAI_API_KEY"] = ""
messages = [{"role": "user", "content": "Write me a poem about the blue sky"}]
completion(model="together_ai/togethercomputer/Llama-2-7B-32K-Instruct", messages=messages)
다른 모델 사용
LiteLLM에 사용자 정의 프롬프트 템플릿을 만들 수 있어요. OpenAssistant/llama2-70b-oasst-sft-v10용으로 만들어 봅시다!
허용되는 템플릿 형식:
"""
system
{system_message}
user
{prompt}
assistant
"""
사용자 정의 프롬프트 템플릿 등록:
import litellm
litellm.register_prompt_template(
model="OpenAssistant/llama2-70b-oasst-sft-v10",
roles={
"system": {
"pre_message": "[system",
"post_message": "\n"
},
"user": {
"pre_message": "user",
"post_message": "\n"
},
"assistant": {
"pre_message": "assistant",
"post_message": "\n"
}
}
)
사용해 보기:
from litellm import completion
# set env variable
os.environ["TOGETHERAI_API_KEY"] = ""
messages=[{"role":"user", "content": "Write me a poem about the blue sky"}]
completion(model="together_ai/OpenAssistant/llama2-70b-oasst-sft-v10", messages=messages)
완전한 코드:
import litellm
from litellm import completion
# set env variable
os.environ["TOGETHERAI_API_KEY"] = ""
litellm.register_prompt_template(
model="OpenAssistant/llama2-70b-oasst-sft-v10",
roles={
"system": {
"pre_message": "[system",
"post_message": "\n"
},
"user": {
"pre_message": "user",
"post_message": "\n"
},
"assistant": {
"pre_message": "assistant",
"post_message": "\n"
}
}
)
messages=[{"role":"user", "content": "Write me a poem about the blue sky"}]
response = completion(model="together_ai/OpenAssistant/llama2-70b-oasst-sft-v10", messages=messages)
print(response)
출력:
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": ".\n\nThe sky is a canvas of blue,\nWith clouds that drift and move,",
"role": "assistant",
"logprobs": null
}
}
],
"created": 1693941410.482018,
"model": "OpenAssistant/llama2-70b-oasst-sft-v10",
"usage": {
"prompt_tokens": 7,
"completion_tokens": 16,
"total_tokens": 23
},
"litellm_call_id": "f21315db-afd6-4c1e-b43a-0b5682de4b06"
}
chat_template_kwargs로 추론 제어
Together는 요청 수준 chat_template_kwargs 객체(Together docs)로 추론 모델을 조정해요. LiteLLM은 SDK와 모든 proxy 엔드포인트(/v1/chat/completions, /v1/messages, /v1/responses)에서 이를 그대로 통과시키며, 스트리밍도 포함돼요. 그러므로 모델에 대해 Together가 문서화한 어떤 키든 그대로 동작해요. Together는 키를 서버 측에서 검증하며 모델이 지원하지 않는 키는 조용히 무시해요.
하이브리드 모델에서 thinking 토글
하이브리드 추론 모델(예: Qwen/Qwen3.5-9B)은 기본적으로 thinking하지만, {"thinking": false}로 끌 수 있어요.
from litellm import completion
import os
os.environ["TOGETHERAI_API_KEY"] = "your-api-key"
response = completion(
model="together_ai/Qwen/Qwen3.5-9B",
messages=[{"role": "user", "content": "What is 17*23? Answer with just the number."}],
chat_template_kwargs={"thinking": False},
)
print(response.choices[0].message.content) # direct answer, no reasoning_content
curl http://0.0.0.0:4000/v1/chat/completions \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3.5-9B",
"messages": [{"role": "user", "content": "What is 17*23? Answer with just the number."}],
"chat_template_kwargs": {"thinking": false}
}'
턴 간 thinking 보존
zai-org/GLM-5.2 같은 모델은 기본적으로 이전 턴의 추론을 프롬프트에서 지워요. {"clear_thinking": false}를 보내면 유지되며, 각 어시스턴트 턴의 reasoning_content를 content와 함께 수정 없이 재생해야 해요. LiteLLM은 재생된 reasoning_content를 Together로 전달하고 자체 기록 필드(thinking_blocks, provider_specific_fields)를 아웃바운드 요청에서 제거하므로, LiteLLM 응답 객체를 그대로 재생해도 안전해요.
from litellm import completion
import os
os.environ["TOGETHERAI_API_KEY"] = "your-api-key"
first = completion(
model="together_ai/zai-org/GLM-5.2",
messages=[{"role": "user", "content": "Pick a secret two-digit number. Reply with only the sum of its digits."}],
)
followup = completion(
model="together_ai/zai-org/GLM-5.2",
messages=[
{"role": "user", "content": "Pick a secret two-digit number. Reply with only the sum of its digits."},
{
"role": "assistant",
"content": first.choices[0].message.content,
"reasoning_content": first.choices[0].message.reasoning_content,
},
{"role": "user", "content": "What was the secret number? Reply with only the number."},
],
chat_template_kwargs={"clear_thinking": False},
)
print(followup.choices[0].message.content) # recalls the number from the replayed reasoning
proxy의 /v1/messages 엔드포인트를 가리키는 Anthropic-SDK 클라이언트도 어시스턴트 thinking 블록을 재생하고 요청 최상위에 chat_template_kwargs: {"clear_thinking": false}를 전달하면 같은 동작을 얻어요.
리랭크
사용법
from litellm import rerank
import os
os.environ["TOGETHERAI_API_KEY"] = "sk-.."
query = "What is the capital of the United States?"
documents = [
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. is the capital of the United States.",
"Capital punishment has existed in the United States since before it was a country.",
]
response = rerank(
model="together_ai/rerank-english-v3.0",
query=query,
documents=documents,
top_n=3,
)
print(response)
LiteLLM은 Rerank 호출을 위한 cohere API 호환 /rerank 엔드포인트를 제공해요. 설정 — 이를 litellm proxy config.yaml에 추가하세요:
model_list:
- model_name: Salesforce/Llama-Rank-V1
litellm_params:
model: together_ai/Salesforce/Llama-Rank-V1
api_key: os.environ/TOGETHERAI_API_KEY
litellm 시작:
litellm --config /path/to/config.yaml
# RUNNING on http://0.0.0.0:4000
테스트 요청:
curl http://0.0.0.0:4000/rerank \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "Salesforce/Llama-Rank-V1",
"query": "What is the capital of the United States?",
"documents": [
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. is the capital of the United States.",
"Capital punishment has existed in the United States since before it was a country."
],
"top_n": 3
}'
더 알아보기 (Learn more)
- Together AI 공식 문서
- Together AI 모델 목록