技能 人工智能 Together AI SDK安装与API配置

Together AI SDK安装与API配置

v20260423
together-install-auth
本指南详细介绍了Together AI SDK的安装和认证流程。它涵盖了使用Python和Node.js两种环境进行SDK的安装,配置必要的API密钥,并验证与OpenAI兼容API的连接。适用于需要进行开源模型推理和精调的开发者。
获取技能
324 次下载
概览

Together AI Install & Auth

Overview

Together AI provides an OpenAI-compatible API for open-source model inference and fine-tuning. Base URL: https://api.together.xyz/v1. Works with the official together Python SDK or any OpenAI-compatible client.

Prerequisites

  • Together AI account at api.together.xyz
  • API key from Settings > API Keys
  • Python 3.8+ or Node.js 18+

Instructions

Step 1: Install SDK

# Python (official)
pip install together

# Node.js (use OpenAI SDK with custom base URL)
npm install openai

Step 2: Configure API Key

# .env
TOGETHER_API_KEY=your-api-key-here

Step 3: Verify Connection (Python)

from together import Together

client = Together(api_key=os.environ["TOGETHER_API_KEY"])
response = client.chat.completions.create(
    model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
    messages=[{"role": "user", "content": "Say hello"}],
    max_tokens=10,
)
print(f"Connected! Response: {response.choices[0].message.content}")

Step 4: Verify with OpenAI Client (Node.js)

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.TOGETHER_API_KEY,
  baseURL: 'https://api.together.xyz/v1',
});

const response = await client.chat.completions.create({
  model: 'meta-llama/Llama-3.3-70B-Instruct-Turbo',
  messages: [{ role: 'user', content: 'Say hello' }],
  max_tokens: 10,
});
console.log(`Connected! ${response.choices[0].message.content}`);

Step 5: List Available Models

models = client.models.list()
for m in models.data[:5]:
    print(f"{m.id} ({m.type})")

Error Handling

Error Cause Solution
401 Unauthorized Invalid API key Check key at api.together.xyz
Model not found Wrong model ID Use client.models.list() to verify
ModuleNotFoundError SDK not installed pip install together
429 Too Many Requests Rate limit Back off and retry

Resources

Next Steps

Proceed to together-hello-world for inference examples.

信息
Category 人工智能
Name together-install-auth
版本 v20260423
大小 2.82KB
更新时间 2026-04-28
语言