together-sdk-patterns

Solid

Together AI sdk patterns for inference, fine-tuning, and model deployment. Use when working with Together AI's OpenAI-compatible API. Trigger: "together sdk patterns".

AI & Automation 2,266 stars 315 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Together AI SDK Patterns ## Overview Production-ready patterns for Together AI inference. Together exposes an OpenAI-compatible REST API at `https://api.together.xyz/v1`, meaning any OpenAI client library works with a base URL swap. This makes Together a drop-in replacement for OpenAI when running open-source models (Llama, Mixtral, Qwen, FLUX). A singleton client centralizes the base URL override and enables seamless backend switching. ## Singleton Client ```typescript import OpenAI from 'openai'; let _client: OpenAI | null = null; export function getClient(): OpenAI { if (!_client) { const apiKey = process.env.TOGETHER_API_KEY; if (!apiKey) throw new Error('TOGETHER_API_KEY must be set — get it from api.together.xyz/settings'); _client = new OpenAI({ apiKey, baseURL: 'https://api.together.xyz/v1' }); } return _client; } // Usage: const client = getClient(); // await client.chat.completions.create({ model: 'meta-llama/Meta-Llama-3.1-70B-Instruct', messages: [...] }); ``` ## Error Wrapper ```typescript export class TogetherError extends Error { constructor(public status: number, public code: string, message: string) { super(message); } } export async function safeCall<T>(operation: string, fn: () => Promise<T>): Promise<T> { try { return await fn(); } catch (err: any) { const status = err.status ?? err.response?.status ?? 0; if (status === 429) { await new Promise(r => setTimeout(r, 3000)); return fn(); } if (status === 401) throw new ...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
7 months ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category