api-ai-together-ai
Together AI SDK patterns for TypeScript — client setup, chat completions, streaming, structured output, function calling, embeddings, image generation, fine-tuning, and OpenAI-compatible endpoints
npx skills add majiayu000/claude-skill-registry --skill api-ai-together-ai --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Describes how to use the Together AI SDK (together-ai) to access open-source models through Together AI's API. It outlines patterns for client setup, chat completions, streaming, structured output with JSON schema, function calling with a tools parameter, image generation, embeddings, and fine-tuning. It also notes compatibility with the OpenAI-like API shape and how to switch base URLs for OpenAI SDK compatibility.
How it works
The skill instructs using the together-ai package (import Together from "together-ai") to initialize a client (env var TOGETHER_API_KEY). It covers:
- Client setup with retries, timeouts, and logging via a configured client instance
- Chat completions using model IDs like meta-llama/Llama-3.3-70B-Instruct-Turbo and a messages array with system and user roles
- Streaming via stream: true and consuming with for await...of
- Structured output by including response_format: { type: "json_schema" } and a JSON schema in both the system prompt and response_format
- Function calling / tool use with a tools array containing function definitions and strict mode
- Image generation via client.images.generate with model and prompt
- Embeddings via client.embeddings.create with a model and input
- Error handling using Together.APIError and subclasses, with specific branches for RateLimitError and AuthenticationError
- OpenAI compatibility by optionally using baseURL to api.together.xyz/v1
It also lists critical requirements and examples covering core patterns, and provides guidance on when to use or not use Together AI features.
When to use it
- Running open-source LLMs (Llama, Qwen, Mistral, DeepSeek) via serverless inference
- Generating images with FLUX or Stable Diffusion models
- Creating embeddings for RAG pipelines with open-source models
- Using function calling / tool use with open-source models
- Extracting structured JSON output from LLM responses
- Fine-tuning open-source models on custom data
- Migrating from OpenAI to open-source models with minimal code changes
What it can touch
The skill references the following tools and methods that the agent can call: the Together client initialization and the methods under client.chat.completions, client.images, client.embeddings, and error types like Together.APIError, Together.RateLimitError, Together.AuthenticationError. It also specifies using the environment variable TOGETHER_API_KEY for credentials. Commands and file names are quoted exactly as shown in the guidance (e.g., import Together from "together-ai", client.chat.completions.create, response_format, tools parameter).
Caveats
- Requires environment variable TOGETHER_API_KEY; keys must not be hardcoded
- Some OpenAI-specific features are not recommended here; for OpenAI-exclusive features, use the OpenAI SDK directly
- Returns and behaviors depend on model capabilities and the Together AI serverless inference service
# Together AI SDK Patterns > **Quick Guide:** Use the `together-ai` npm package to access 200+ open-source models (Llama, Qwen, Mistral, DeepSeek) via Together AI's fast inference API. The SDK mirrors the OpenAI API shape -- `client.chat.completions.create()` for chat, `client.images.generate()` for images, `client.embeddings.create()` for embeddings. Use `response_format: { type: "json_schema" }` with Zod-generated schemas for structured output. Function calling uses the same `tools` parameter shape as OpenAI. You can also use the OpenAI SDK directly by pointing `baseURL` to `https://api.together.xyz/v1`. --- <critical_requirements> ## CRITICAL: Before Using This Skill > **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants) **(You MUST use the `together-ai` package (`import Together from "together-ai"`) -- NOT the OpenAI SDK -- unless explicitly building an OpenAI-compatible integration)** **(You MUST include the JSON schema in BOTH the `response_format` parameter AND the system prompt when using structured output -- the model needs both)** **(You MUST handle errors using `Together.APIError` and its s
- CRITICAL: Before Using This Skill
- Examples Index
- Philosophy
- Core Patterns
- Pattern 1: Client Setup
- Pattern 2: Chat Completions
- Pattern 3: Streaming
- Pattern 4: Structured Output with JSON Schema
- Pattern 5: Function Calling / Tool Use
- Pattern 6: Image Generation
- Pattern 7: Embeddings
- Pattern 8: Error Handling
- Performance Optimization
- Model Selection for Cost/Speed
What does the api-ai-together-ai skill do?
Together AI SDK patterns for TypeScript — client setup, chat completions, streaming, structured output, function calling, embeddings, image generation, fine-tuning, and OpenAI-compatible endpoints
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill api-ai-together-ai --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
