Together AI攻略:开源 LLM 推理云——Llama/Mistral 等开源大模型企业部署热门。
Together AI 是一家面向开发者和企业的开源大模型推理云平台。它聚合了 Llama、Mistral、DeepSeek、Qwen 等主流开源模型,提供统一的 API 接口,让用户无需自建 GPU 集群就能调用高性能的开源大模型。核心定位是“开源 LLM 的一站式推理服务”——你写代码调用 API,它负责跑模型、算结果。
适合人群:
不适合人群:
注册账号
安装 SDK
pip install together
写第一行代码
from together import Together
client = Together(api_key="你的API_KEY")
response = client.chat.completions.create(
model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
messages=[{"role": "user", "content": "用一句话解释量子计算"}]
)
print(response.choices[0].message.content)
运行成功即完成首次调用。注意:模型名称需从官方文档复制,大小写敏感。
理解不同模型
参数调优
response = client.chat.completions.create(
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
messages=[...],
temperature=0.7, # 控制随机性,0-2
max_tokens=1024, # 最大输出长度
top_p=0.9, # 核采样
stop=["\n\n"] # 停止词
)
流式输出
stream = client.chat.completions.create(
model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
messages=[...],
stream=True
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
函数调用(Function Calling)
让模型返回结构化 JSON,适合构建工具调用链:
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}}
}
}
}
]
response = client.chat.completions.create(
model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
messages=[...],
tools=tools
)
嵌入(Embeddings)
将文本转为向量,用于语义搜索或 RAG:
response = client.embeddings.create(
model="BAAI/bge-base-en-v1.5",
input=["文本内容"]
)
批量处理与缓存
together.Files 上传批量数据计费模式:按 token 计费,输入和输出分开计价。
典型模型价格(每百万 token):
省钱策略:
max_tokens,避免模型无限制生成付费方式:支持信用卡和 PayPal,无国内支付渠道。
如果 Together AI 不满足你的需求,可以考虑以下替代方案:
决策建议: