⚠️ 待更新·2026-08-29核验 · 更新时间待核验 · 本文信息可能已过期,请以官方文档为准
更新时间:2026-08-29 · 核验状态:待更新 · 官方溯源待补
简介
Together AI 是一家主打开源模型托管的服务商,提供 Llama、Qwen、DeepSeek 等数百个模型的推理 API,且新用户注册即送 $5 额度,足够跑数十万 token。本篇演示从注册到首次调用的完整流程,并介绍图像生成等扩展能力。
架构图
flowchart TD
A[Sign up at together.ai] --> B[Verify email]
B --> C[Claim $5 welcome credit]
C --> D[Create API Key]
D --> E[Call Llama 3.3 70B]
E --> F[OpenAI-compatible endpoint]
注册并领取额度
- 打开 https://www.together.ai,点击 Sign Up,用 Google 或 GitHub 登录。
- 进入 https://api.together.ai/settings/billing,新账号会自动到账 $5 信用额度。
- 如未自动到账,在 Dashboard 输入邀请码或联系 support@together.ai。
- 在 https://api.together.ai/settings/api-keys 创建 API Key,复制
xxxxx... 字符串。
建议把 Key 按用途分:一把用于本地开发、一把用于 CI(设 $1 上限防刷爆)。
安装与配置
Together AI 完全兼容 OpenAI 协议,直接用 openai SDK 即可:
pip install openai
export TOGETHER_API_KEY="..."
调用示例
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOGETHER_API_KEY"],
base_url="https://api.together.xyz/v1",
)
resp = client.chat.completions.create(
model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
messages=[
{"role": "system", "content": "你是简洁的中文助手"},
{"role": "user", "content": "用一句话解释什么是反向索引"},
],
temperature=0.3,
max_tokens=256,
)
print(resp.choices[0].message.content)
图像生成
Together 也托管 Stable Diffusion / FLUX:
import requests, os, base64
r = requests.post(
"https://api.together.xyz/v1/images/generations",
headers={"Authorization": f"Bearer {os.environ['TOGETHER_API_KEY']}"},
json={
"model": "black-forest-labs/FLUX.1-schnell-Free",
"prompt": "a serene mountain lake at sunrise",
"n": 1,
},
)
img_b64 = r.json()["data"][0]["b64_json"]
with open("lake.png", "wb") as f:
f.write(base64.b64decode(img_b64))
浏览可用模型
curl https://api.together.xyz/v1/models \
-H "Authorization: Bearer $TOGETHER_API_KEY" | jq '.data[].id' | head
或者直接看 https://docs.together.ai/docs/inference-models 的列表,带 :free 的模型不计费但限速。
成本估算
以 Llama-3.3-70B-Instruct-Turbo 为例:
- 输入:$0.88 / 1M tokens
- 输出:$0.88 / 1M tokens
$5 额度大约能跑 5M tokens 的对话,够原型验证一两周。Turbo 系列比原版便宜 3-5 倍,优先选。
模型选型与成本优化
Together 上的模型分三档::free 完全免费但限速严格;Turbo 系列经过量化优化,性价比最高;原版价格较高但精度最佳。日常开发优先选 Turbo,如 Llama-3.3-70B-Instruct-Turbo 比原版便宜 3-5 倍。中文场景推荐 Qwen/Qwen2.5-72B-Instruct-Turbo,代码场景可用 Qwen/Qwen2.5-Coder-32B-Instruct。
常见问题
401 unauthorized:检查 API Key 是否完整复制,注意前后无空格。
model not found:模型 ID 区分大小写,以 /v1/models 返回为准。
- 额度用完怎么办:绑卡后按量付费,或继续用 OpenRouter 上的
:free 模型过渡。
- 想微调模型:Together 提供 Fine-tuning API,在 https://docs.together.ai/docs/fine-tuning 查看文档。
Together AI 是开源模型商用的性价比之选。
最佳实践
- $5 信用够跑 500-1000 次调用:Llama 3.3 70B 大约 $0.6/M token,5 美元能跑很久。
- Together 比 OpenRouter 直连快:直连省一层网络跳,延迟低 50-100ms。
- Quantized 模型更便宜:
Llama-3.3-70B-Instruct-Turbo 量化版价格是 FP16 的 1/3。
- 用 OpenAI SDK 直接接:只需改
base_url 和 api_key,其他代码不动。
⚠️ Pending Update · 2026-08-29 Verification · Content may be outdated, please refer to official docs
Updated: 2026-08-29 · Status: Pending Verification
Introduction
Together AI is a hosting provider focused on open-source models, offering inference APIs for hundreds of models including Llama, Qwen, and DeepSeek. New accounts get a $5 welcome credit — enough for several hundred thousand tokens. This article walks through signup, your first call, and image generation.
架构图
flowchart TD
A[Sign up at together.ai] --> B[Verify email]
B --> C[Claim $5 welcome credit]
C --> D[Create API Key]
D --> E[Call Llama 3.3 70B]
E --> F[OpenAI-compatible endpoint]
Sign Up and Claim Credits
- Open https://www.together.ai and click Sign Up. Log in with Google or GitHub.
- Go to https://api.together.ai/settings/billing. The $5 credit is automatically credited to new accounts.
- If it does not appear, enter a referral code on the Dashboard or email support@together.ai.
- Create an API key at https://api.together.ai/settings/api-keys and copy the
xxxxx... string.
Split keys by purpose: one for local development, another for CI with a $1 cap to prevent runaway spend.
Together AI is fully OpenAI-compatible, so the openai SDK works directly:
pip install openai
export TOGETHER_API_KEY="..."
Example Call
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOGETHER_API_KEY"],
base_url="https://api.together.xyz/v1",
)
resp = client.chat.completions.create(
model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain an inverted index in one sentence."},
],
temperature=0.3,
max_tokens=256,
)
print(resp.choices[0].message.content)
Image Generation
Together also hosts Stable Diffusion / FLUX:
import requests, os, base64
r = requests.post(
"https://api.together.xyz/v1/images/generations",
headers={"Authorization": f"Bearer {os.environ['TOGETHER_API_KEY']}"},
json={
"model": "black-forest-labs/FLUX.1-schnell-Free",
"prompt": "a serene mountain lake at sunrise",
"n": 1,
},
)
img_b64 = r.json()["data"][0]["b64_json"]
with open("lake.png", "wb") as f:
f.write(base64.b64decode(img_b64))
Browse Available Models
curl https://api.together.xyz/v1/models \
-H "Authorization: Bearer $TOGETHER_API_KEY" | jq '.data[].id' | head
Or browse https://docs.together.ai/docs/inference-models. Models with :free are free but rate-limited.
Cost Estimation
For Llama-3.3-70B-Instruct-Turbo:
- Input: $0.88 / 1M tokens
- Output: $0.88 / 1M tokens
The $5 credit buys roughly 5M tokens — enough for one to two weeks of prototyping. Turbo variants are 3-5x cheaper than the base; prefer them.
Model Selection and Cost Optimization
Together models fall into three tiers: :free (fully free but strictly rate-limited), Turbo variants (quantized for the best price/performance), and the original (highest accuracy, higher price). For daily development prefer Turbo — Llama-3.3-70B-Instruct-Turbo is 3-5x cheaper than the base. For Chinese, try Qwen/Qwen2.5-72B-Instruct-Turbo; for code, Qwen/Qwen2.5-Coder-32B-Instruct.
Troubleshooting
401 unauthorized: Make sure the key was copied in full with no leading or trailing spaces.
model not found: Model IDs are case-sensitive. Trust the list returned by /v1/models.
- Out of credit: Add a card for pay-as-you-go, or fall back to
:free models on OpenRouter.
- Fine-tuning: Together offers a Fine-tuning API — see https://docs.together.ai/docs/fine-tuning.
Together AI is a cost-effective choice for commercializing open-source models.
Best Practices
- $5 credit buys 500-1000 calls: Llama 3.3 70B is about $0.6/M token, so $5 lasts a while.
- Together direct is faster than via OpenRouter: skipping a network hop saves 50-100ms latency.
- Quantized models are cheaper:
Llama-3.3-70B-Instruct-Turbo quantized is 1/3 the price of FP16.
- Use the OpenAI SDK directly: just swap
base_url and api_key, leave the rest of your code unchanged.