[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6XFNNM446TQ1M6PVW5WCJQ0":3,"skill-same:01M6XFNNM446TQ1M6PVW5WCJQ0":78},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":58,"commitSha":59,"skillDirectory":60,"forksCount":14,"repositoryHtmlUrl":61,"repositoryHomepageUrl":6,"ownerHtmlUrl":62,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":63,"install":64,"resources":77},"01M6XFNNM446TQ1M6PVW5WCJQ0","together-ai-inference",null,"Serverless inference, fine-tuning, embeddings, image generation, and batch processing on 200+ open-source models via an OpenAI-compatible API. Use when you need fast, cost-effective access to open-source LLMs without managing infrastructure.","fadrienne\u002FMyGitHub","fadrienne","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F197874571?v=4","01M6X64V8VWCRSMFZ4EPS2BWXG","Francesca Adrienne","01M6X64VD5MW4F9PHDWQKS7ZAF",0,"MIT","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fopenscience\u002Fbackend\u002Fcli\u002Fskills\u002Fcloud-compute\u002Ftogether-ai\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"together ai inference","inference","together ai","access","when","source","openai-compatible","you","processing","synthetic","use","image","open","api","tuning","embeddings","batch","openai","infrastructure","llms","2026-11-10 10:12:30",false,"---\nname: together-ai-inference\ndescription: Serverless inference, fine-tuning, embeddings, image generation, and batch processing on 200+ open-source models via an OpenAI-compatible API. Use when you need fast, cost-effective access to open-source LLMs without managing infrastructure.\ncategory: cloud-compute\nversion: 1.0.0\nauthor: Synthetic Sciences\nlicense: MIT\ntags: [Inference, Together AI, Fine-Tuning, Embeddings, Serverless, OpenAI-Compatible, Batch, Image Generation]\ndependencies: [together, openai]\n---\n\n# Together AI — Serverless Inference & Fine-Tuning\n\nTogether AI is an AI cloud platform providing serverless inference on 200+ open-source models through an OpenAI-compatible API. It supports chat completions, embeddings, fine-tuning, image generation, and batch processing at `https:\u002F\u002Fapi.together.xyz\u002Fv1`.\n\n## When to Use Together AI\n\n**Use Together AI when:**\n- You need fast serverless inference on open-source models (Llama, DeepSeek, Qwen, Mistral)\n- You want an OpenAI-compatible API so you can swap providers with a single line change\n- You need to fine-tune open-source models without managing GPU infrastructure\n- You want cost-effective inference with pay-per-token pricing\n- You need function calling, JSON mode, or structured outputs from open-source models\n- You want batch processing at 50% lower cost for non-urgent workloads\n- You need embeddings or image generation alongside chat completions\n\n**Use alternatives instead:**\n\n| Need | Use Instead |\n|------|-------------|\n| Managed LoRA fine-tuning with training platform | **Tinker** |\n| Self-hosted inference with full control | **vLLM**, **TensorRT-LLM** |\n| Dedicated GPU instances | **Lambda Labs**, **RunPod** |\n| Serverless GPU with custom containers | **Modal** |\n| Multi-cloud cost optimization | **SkyPilot** |\n| Proprietary models (GPT-4o, Claude) | **OpenAI**, **Anthropic** directly |\n\n\n## Credential Setup\n\nCredentials are auto-injected by openscience when connected via the dashboard.\n\n```bash\n# Verify credentials\n[ -n \"$TOGETHER_API_KEY\" ] && echo \"TOGETHER_API_KEY set\" || echo \"NOT SET\"\n```\n\nIf not set: connect Together AI at https:\u002F\u002Fapp.syntheticsciences.ai -> Services, then restart openscience.\n\n## Quick Start\n\n### Install\n\n```python\npip install together openai\n```\n\n### Set API Key\n\n```python\nimport os\nos.environ[\"TOGETHER_API_KEY\"] = \"your-api-key\"\n\n# Or export in shell:\n# export TOGETHER_API_KEY=\"your-api-key\"\n```\n\nGet your API key from https:\u002F\u002Fapi.together.xyz\u002Fsettings\u002Fapi-keys\n\n### Basic Chat Completion\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Explain gradient descent in one paragraph.\"},\n    ],\n    max_tokens=256,\n    temperature=0.7,\n)\n\nprint(response.choices[0].message.content)\n```\n\n## Inference\n\n### Chat Completions\n\nThe primary endpoint for conversational AI. Supports system\u002Fuser\u002Fassistant messages, temperature, top_p, top_k, repetition_penalty, and stop sequences.\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.chat.completions.create(\n    model=\"deepseek-ai\u002FDeepSeek-V3\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are an expert ML researcher.\"},\n        {\"role\": \"user\", \"content\": \"Compare LoRA vs full fine-tuning.\"},\n    ],\n    max_tokens=512,\n    temperature=0.7,\n    top_p=0.9,\n    top_k=50,\n    repetition_penalty=1.1,\n    stop=[\"\u003C\u002Fs>\"],\n)\n\nprint(response.choices[0].message.content)\nprint(f\"Tokens used: {response.usage.total_tokens}\")\n```\n\n### Streaming\n\n```python\nfrom together import Together\n\nclient = Together()\n\nstream = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[{\"role\": \"user\", \"content\": \"Write a haiku about transformers.\"}],\n    max_tokens=128,\n    stream=True,\n)\n\nfor chunk in stream:\n    delta = chunk.choices[0].delta.content\n    if delta:\n        print(delta, end=\"\", flush=True)\nprint()\n```\n\n### Function Calling\n\nSupported on select models including Llama, DeepSeek, Qwen, and Mistral variants.\n\n```python\nfrom together import Together\nimport json\n\nclient = Together()\n\ntools = [\n    {\n        \"type\": \"function\",\n        \"function\": {\n            \"name\": \"get_weather\",\n            \"description\": \"Get the current weather for a location\",\n            \"parameters\": {\n                \"type\": \"object\",\n                \"properties\": {\n                    \"location\": {\n                        \"type\": \"string\",\n                        \"description\": \"City and state, e.g. San Francisco, CA\",\n                    },\n                    \"unit\": {\n                        \"type\": \"string\",\n                        \"enum\": [\"celsius\", \"fahrenheit\"],\n                    },\n                },\n                \"required\": [\"location\"],\n            },\n        },\n    }\n]\n\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"What's the weather in San Francisco?\"},\n    ],\n    tools=tools,\n    tool_choice=\"auto\",\n)\n\ntool_calls = response.choices[0].message.tool_calls\nif tool_calls:\n    call = tool_calls[0]\n    print(f\"Function: {call.function.name}\")\n    print(f\"Arguments: {call.function.arguments}\")\n```\n\n### JSON Mode (Structured Outputs)\n\nForce the model to return valid JSON conforming to a schema.\n\n```python\nimport json\nfrom together import Together\n\nclient = Together()\n\nschema = {\n    \"type\": \"object\",\n    \"properties\": {\n        \"name\": {\"type\": \"string\"},\n        \"age\": {\"type\": \"integer\"},\n        \"skills\": {\"type\": \"array\", \"items\": {\"type\": \"string\"}},\n    },\n    \"required\": [\"name\", \"age\", \"skills\"],\n}\n\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[\n        {\n            \"role\": \"system\",\n            \"content\": f\"Respond only in JSON matching this schema: {json.dumps(schema)}\",\n        },\n        {\"role\": \"user\", \"content\": \"Create a profile for a senior ML engineer.\"},\n    ],\n    response_format={\n        \"type\": \"json_object\",\n        \"schema\": schema,\n    },\n)\n\ndata = json.loads(response.choices[0].message.content)\nprint(json.dumps(data, indent=2))\n```\n\n### Vision Models\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-4-Scout-17B-16E-Instruct-VLM\",\n    messages=[\n        {\n            \"role\": \"user\",\n            \"content\": [\n                {\"type\": \"text\", \"text\": \"Describe this image in detail.\"},\n                {\n                    \"type\": \"image_url\",\n                    \"image_url\": {\"url\": \"https:\u002F\u002Fexample.com\u002Fimage.jpg\"},\n                },\n            ],\n        }\n    ],\n    max_tokens=512,\n)\n\nprint(response.choices[0].message.content)\n```\n\n## Fine-Tuning\n\nTogether AI supports both LoRA and full fine-tuning on a wide range of open-source models.\n\n### Data Format\n\nTraining data must be in JSONL format with chat-style messages:\n\n```jsonl\n{\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}, {\"role\": \"user\", \"content\": \"What is the capital of France?\"}, {\"role\": \"assistant\", \"content\": \"The capital of France is Paris.\"}]}\n{\"messages\": [{\"role\": \"user\", \"content\": \"Explain photosynthesis.\"}, {\"role\": \"assistant\", \"content\": \"Photosynthesis is the process by which plants convert sunlight, water, and carbon dioxide into glucose and oxygen.\"}]}\n```\n\nEach line is one training example. The `system` role is optional. The model learns to generate the `assistant` responses.\n\n### Upload Training Data\n\n```python\nfrom together import Together\n\nclient = Together()\n\n# Upload training file\nfile = client.files.upload(file=\"training_data.jsonl\")\nprint(f\"File ID: {file.id}\")\n```\n\n### Create Fine-Tuning Job\n\n```python\nfrom together import Together\n\nclient = Together()\n\n# Create LoRA fine-tuning job\njob = client.fine_tuning.create(\n    training_file=\"file-abc123\",\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    n_epochs=3,\n    learning_rate=1e-5,\n    batch_size=4,\n    lora=True,\n    lora_r=16,\n    lora_alpha=32,\n    lora_dropout=0.05,\n    suffix=\"my-custom-model\",\n)\n\nprint(f\"Job ID: {job.id}\")\nprint(f\"Status: {job.status}\")\n```\n\n### Monitor Fine-Tuning\n\n```python\nfrom together import Together\n\nclient = Together()\n\n# Check job status\njob = client.fine_tuning.retrieve(id=\"ft-abc123\")\nprint(f\"Status: {job.status}\")\n\n# List all jobs\njobs = client.fine_tuning.list()\nfor j in jobs:\n    print(f\"{j.id}: {j.status}\")\n\n# List events (training logs)\nevents = client.fine_tuning.list_events(id=\"ft-abc123\")\nfor event in events:\n    print(event)\n\n# Cancel a job\nclient.fine_tuning.cancel(id=\"ft-abc123\")\n```\n\n### CLI Fine-Tuning\n\n```bash\n# Install CLI\npip install --upgrade together\n\n# Upload data\ntogether files upload training_data.jsonl\n\n# Create fine-tuning job\ntogether fine-tuning create \\\n    --training-file file-abc123 \\\n    -m meta-llama\u002FMeta-Llama-3.1-8B-Instruct-Reference\n\n# Check status\ntogether fine-tuning status ft-abc123\n\n# List checkpoints\ntogether fine-tuning list-checkpoints ft-abc123\n\n# Download fine-tuned model\ntogether fine-tuning download --ft-id ft-abc123\n```\n\n### Supported Fine-Tuning Models (Selection)\n\n| Model | LoRA | Full |\n|-------|------|------|\n| meta-llama\u002FMeta-Llama-3.1-8B-Instruct-Reference | Yes | Yes |\n| meta-llama\u002FLlama-3.3-70B-Instruct-Reference | Yes | Yes |\n| meta-llama\u002FLlama-4-Scout-17B-16E-Instruct | Yes | No |\n| deepseek-ai\u002FDeepSeek-V3 | Yes | No |\n| deepseek-ai\u002FDeepSeek-R1 | Yes | No |\n| Qwen\u002FQwen3-8B | Yes | Yes |\n| Qwen\u002FQwen3-32B | Yes | Yes |\n| Qwen\u002FQwen3-235B-A22B | Yes | No |\n| google\u002Fgemma-3-27b-it | Yes | Yes |\n| google\u002Fgemma-3-4b-it | Yes | Yes |\n\nSee the full list at https:\u002F\u002Fdocs.together.ai\u002Fdocs\u002Ffine-tuning-models\n\n## Embeddings\n\n### Generate Embeddings\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.embeddings.create(\n    model=\"BAAI\u002Fbge-large-en-v1.5\",\n    input=\"What is the meaning of life?\",\n)\n\nembedding = response.data[0].embedding\nprint(f\"Dimensions: {len(embedding)}\")\nprint(f\"First 5 values: {embedding[:5]}\")\n```\n\n### Batch Embeddings\n\n```python\nfrom together import Together\n\nclient = Together()\n\ntexts = [\n    \"Machine learning is a subset of AI.\",\n    \"Deep learning uses neural networks.\",\n    \"Transformers revolutionized NLP.\",\n]\n\nresponse = client.embeddings.create(\n    model=\"BAAI\u002Fbge-large-en-v1.5\",\n    input=texts,\n)\n\nfor i, item in enumerate(response.data):\n    print(f\"Text {i}: {len(item.embedding)} dimensions\")\n```\n\n### Available Embedding Models\n\n| Model ID | Dimensions | Best For |\n|----------|-----------|----------|\n| `BAAI\u002Fbge-large-en-v1.5` | 1024 | General-purpose English retrieval |\n| `BAAI\u002Fbge-base-en-v1.5` | 768 | Balanced performance and cost |\n| `WhereIsAI\u002FUAE-Large-V1` | 1024 | High-accuracy retrieval |\n| `togethercomputer\u002Fm2-bert-80M-8k-retrieval` | 768 | Long-context (8k tokens) retrieval |\n\n## Image Generation\n\nTogether AI hosts FLUX models from Black Forest Labs for high-quality image generation.\n\n### Generate Images\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.images.generate(\n    model=\"black-forest-labs\u002FFLUX.1-schnell\",\n    prompt=\"A photorealistic mountain landscape at sunset with a lake reflection\",\n    steps=4,\n    n=1,\n    width=1024,\n    height=1024,\n)\n\n# Response contains URL or base64 image data\nprint(response.data[0].url)\n```\n\n### Available Image Models\n\n| Model ID | Type | Notes |\n|----------|------|-------|\n| `black-forest-labs\u002FFLUX.1-schnell` | Fast generation | Fastest, lower step count (4 steps) |\n| `black-forest-labs\u002FFLUX.1-dev` | Development | LoRA support for custom styles |\n| `black-forest-labs\u002FFLUX.1.1-pro` | Premium | Highest quality, best prompt adherence |\n\n### Image with OpenAI SDK\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI(\n    api_key=os.environ[\"TOGETHER_API_KEY\"],\n    base_url=\"https:\u002F\u002Fapi.together.xyz\u002Fv1\",\n)\n\nresponse = client.images.generate(\n    model=\"black-forest-labs\u002FFLUX.1-schnell\",\n    prompt=\"A cyberpunk cityscape at night\",\n    n=1,\n)\n\nprint(response.data[0].url)\n```\n\n## Batch Inference\n\nBatch API processes large volumes of requests asynchronously at 50% lower cost with a 24-hour turnaround.\n\n### Input File Format\n\nCreate a JSONL file where each line is a request:\n\n```jsonl\n{\"custom_id\": \"request-1\", \"body\": {\"model\": \"deepseek-ai\u002FDeepSeek-V3\", \"messages\": [{\"role\": \"user\", \"content\": \"What is machine learning?\"}], \"max_tokens\": 200}}\n{\"custom_id\": \"request-2\", \"body\": {\"model\": \"deepseek-ai\u002FDeepSeek-V3\", \"messages\": [{\"role\": \"user\", \"content\": \"Explain gradient descent.\"}], \"max_tokens\": 200}}\n{\"custom_id\": \"request-3\", \"body\": {\"model\": \"deepseek-ai\u002FDeepSeek-V3\", \"messages\": [{\"role\": \"user\", \"content\": \"What are transformers?\"}], \"max_tokens\": 200}}\n```\n\n### Submit Batch Job\n\n```python\nfrom together import Together\n\nclient = Together()\n\n# 1. Upload the batch file\nbatch_file = client.files.upload(\n    file=\"batch_requests.jsonl\",\n    purpose=\"batch-api\",\n)\nprint(f\"File ID: {batch_file.id}\")\n\n# 2. Create the batch job\nbatch = client.batches.create_batch(\n    file_id=batch_file.id,\n    endpoint=\"\u002Fv1\u002Fchat\u002Fcompletions\",\n)\nprint(f\"Batch ID: {batch.id}\")\n\n# 3. Monitor status\nstatus = client.batches.get_batch(batch.id)\nprint(f\"Status: {status.status}\")\n\n# 4. Download results when completed\nif status.status == \"COMPLETED\":\n    results = client.files.retrieve_content(\n        id=status.output_file_id,\n    )\n    print(results)\n```\n\n### List Batches\n\n```python\nfrom together import Together\n\nclient = Together()\n\nbatches = client.batches.list_batches()\nfor b in batches:\n    print(f\"{b.id}: {b.status}\")\n```\n\n## Model Selection\n\n### Chat \u002F Instruct Models\n\n| Model ID | Params | Input $\u002FM | Output $\u002FM | Context | Best For |\n|----------|--------|-----------|------------|---------|----------|\n| `meta-llama\u002FMeta-Llama-3.1-8B-Instruct-Reference` | 8B | $0.18 | $0.18 | 131k | Fast, cheap general tasks |\n| `meta-llama\u002FLlama-3.3-70B-Instruct-Reference` | 70B | $0.88 | $0.88 | 131k | High-quality general purpose |\n| `meta-llama\u002FLlama-4-Maverick-17B-128E-Instruct` | 400B MoE | $0.27 | $0.85 | 1M | Cost-effective large model |\n| `deepseek-ai\u002FDeepSeek-V3` | 671B MoE | $1.25 | $1.25 | 128k | Top-tier reasoning and code |\n| `deepseek-ai\u002FDeepSeek-R1` | 671B MoE | $3.00 | $7.00 | 128k | Complex reasoning with CoT |\n| `Qwen\u002FQwen3-Next-80B-A3B-Instruct` | 80B MoE | $0.15 | $1.50 | 128k | Ultra-cheap MoE inference |\n| `Qwen\u002FQwen3-235B-A22B` | 235B MoE | $0.50 | $1.50 | 128k | Powerful open-weight MoE |\n| `mistralai\u002FMixtral-8x7B-Instruct-v0.1` | 46B MoE | $0.60 | $0.60 | 32k | Balanced MoE model |\n| `Qwen\u002FQwen3-Coder-480B-A35B-Instruct` | 480B MoE | $0.60 | $1.80 | 256k | Code generation and review |\n| `google\u002Fgemma-3-27b-it` | 27B | $0.30 | $0.30 | 128k | Google's efficient model |\n\n### Reasoning Models\n\n| Model ID | Input $\u002FM | Output $\u002FM | Notes |\n|----------|-----------|------------|-------|\n| `deepseek-ai\u002FDeepSeek-R1` | $3.00 | $7.00 | Chain-of-thought reasoning |\n| `deepseek-ai\u002FDeepSeek-R1-0528` | $3.00 | $7.00 | Updated R1 variant |\n| `Qwen\u002FQwen3-Next-80B-A3B-Thinking` | $0.15 | $1.50 | MoE reasoning, very cheap |\n\n### Code Models\n\n| Model ID | Input $\u002FM | Output $\u002FM | Notes |\n|----------|-----------|------------|-------|\n| `Qwen\u002FQwen3-Coder-30B-A3B-Instruct` | $0.15 | $1.50 | Fast code MoE |\n| `Qwen\u002FQwen3-Coder-480B-A35B-Instruct` | $0.60 | $1.80 | Largest code model |\n\nPricing is approximate and subject to change. Check https:\u002F\u002Fwww.together.ai\u002Fpricing for current rates.\n\n## OpenAI Compatibility\n\nTogether AI is fully compatible with the OpenAI Python SDK. Change two lines to switch from OpenAI to Together AI.\n\n### Using OpenAI SDK\n\n```python\nfrom openai import OpenAI\nimport os\n\n# Just change the API key and base_url\nclient = OpenAI(\n    api_key=os.environ[\"TOGETHER_API_KEY\"],\n    base_url=\"https:\u002F\u002Fapi.together.xyz\u002Fv1\",\n)\n\n# Everything else is identical to OpenAI usage\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Hello!\"},\n    ],\n    max_tokens=256,\n)\n\nprint(response.choices[0].message.content)\n```\n\n### What Works with OpenAI SDK\n\n| Feature | Supported |\n|---------|-----------|\n| `chat.completions.create` | Yes |\n| Streaming responses | Yes |\n| Function calling \u002F tools | Yes |\n| JSON mode \u002F structured outputs | Yes |\n| Vision (multimodal) | Yes |\n| `embeddings.create` | Yes |\n| `images.generate` | Yes |\n| `fine_tuning.jobs.create` | Yes |\n| `models.list` | Yes |\n| Async client | Yes |\n| `.with_raw_response` | Yes |\n| `.with_streaming_response` | Yes |\n\n### LangChain Integration\n\n```python\nfrom langchain_openai import ChatOpenAI\n\nllm = ChatOpenAI(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    openai_api_key=os.environ[\"TOGETHER_API_KEY\"],\n    openai_api_base=\"https:\u002F\u002Fapi.together.xyz\u002Fv1\",\n)\n\nresponse = llm.invoke(\"What is the meaning of life?\")\nprint(response.content)\n```\n\n## CLI Reference\n\nThe `together` CLI provides direct access from the terminal.\n\n```bash\n# Install\npip install --upgrade together\n\n# Set API key\nexport TOGETHER_API_KEY=\"your-api-key\"\n\n# Chat completion\ntogether chat.completions \\\n    --message \"system\" \"You are helpful.\" \\\n    --message \"user\" \"What is PyTorch?\" \\\n    --model meta-llama\u002FLlama-3.3-70B-Instruct-Reference\n\n# List models\ntogether models list\n\n# Image generation\ntogether images generate \\\n    \"A futuristic city at sunset\" \\\n    --model black-forest-labs\u002FFLUX.1-schnell \\\n    --n 1\n\n# File operations\ntogether files upload training_data.jsonl\ntogether files list\ntogether files retrieve file-abc123\ntogether files delete file-abc123\n\n# Fine-tuning\ntogether fine-tuning create \\\n    --training-file file-abc123 \\\n    -m meta-llama\u002FMeta-Llama-3.1-8B-Instruct-Reference\ntogether fine-tuning list\ntogether fine-tuning status ft-abc123\ntogether fine-tuning list-events ft-abc123\ntogether fine-tuning list-checkpoints ft-abc123\ntogether fine-tuning download --ft-id ft-abc123\ntogether fine-tuning cancel ft-abc123\n```\n\n## Cost Optimization\n\n### 1. Use MoE Models\n\nMixture-of-Experts models activate only a fraction of parameters per token, offering better price-to-performance:\n\n| Model | Active Params | Price |\n|-------|--------------|-------|\n| Qwen3-Next-80B-A3B | 3B active of 80B | $0.15\u002FM input |\n| Llama-4-Maverick | 17B active of 400B | $0.27\u002FM input |\n| DeepSeek-V3 | ~37B active of 671B | $1.25\u002FM input |\n\n### 2. Use Batch API\n\nSubmit non-urgent workloads via the batch API for 50% cost reduction. Ideal for evaluations, dataset generation, and bulk classification.\n\n### 3. Use JSON Mode for Structured Output\n\nAvoid post-processing errors and retry loops by constraining output format upfront.\n\n### 4. Right-Size Your Model\n\n- **Simple classification\u002Fextraction**: 8B models ($0.18\u002FM)\n- **General chat\u002Finstruction**: 70B models ($0.88\u002FM)\n- **Complex reasoning\u002Fcode**: DeepSeek-V3 ($1.25\u002FM) or R1 ($3.00\u002FM)\n- **Cost-sensitive high volume**: MoE models like Qwen3-Next ($0.15\u002FM)\n\n### 5. Minimize Max Tokens\n\nSet `max_tokens` to the minimum needed. You pay for output tokens generated, not the max_tokens budget.\n\n### 6. Use Streaming for Long Outputs\n\nStreaming does not cost more but gives faster time-to-first-token and lets you abort early if the output goes off track.\n\n## Common Issues\n\n| Problem | Solution |\n|---------|----------|\n| `401 Unauthorized` | Check `TOGETHER_API_KEY` is set and valid |\n| `429 Rate Limited` | Implement exponential backoff; upgrade plan for higher limits |\n| `Model not found` | Verify model ID at https:\u002F\u002Fdocs.together.ai\u002Fdocs\u002Fserverless-models |\n| JSON mode returns invalid JSON | Include the schema in the system prompt alongside `response_format` |\n| Function calling not working | Use supported models (Llama 3.x, DeepSeek, Qwen3, Mistral) |\n| Fine-tuning job stuck | Check data format (must be valid JSONL with `messages` array) |\n| Batch job failed | Verify JSONL format has `custom_id` and `body` fields per line |\n| Slow response times | Try Turbo\u002FLite model variants or reduce `max_tokens` |\n| Embedding dimensions mismatch | Different models produce different dimensions (768 or 1024) |\n| Image generation timeout | Reduce `steps` parameter; use FLUX.1-schnell for fastest results |\n\n## Resources\n\n- **Documentation**: https:\u002F\u002Fdocs.together.ai\n- **API Reference**: https:\u002F\u002Fdocs.together.ai\u002Freference\n- **Pricing**: https:\u002F\u002Fwww.together.ai\u002Fpricing\n- **Dashboard**: https:\u002F\u002Fapi.together.xyz\n- **Model Catalog**: https:\u002F\u002Fdocs.together.ai\u002Fdocs\u002Fserverless-models\n- **Fine-Tuning Guide**: https:\u002F\u002Fdocs.together.ai\u002Fdocs\u002Ffine-tuning-quickstart\n- **Python SDK**: https:\u002F\u002Fgithub.com\u002Ftogethercomputer\u002Ftogether-python\n- **TypeScript SDK**: https:\u002F\u002Fgithub.com\u002Ftogethercomputer\u002Ftogether-typescript\n- **Cookbook (Examples)**: https:\u002F\u002Fgithub.com\u002Ftogethercomputer\u002Ftogether-cookbook\n- **Status Page**: https:\u002F\u002Fstatus.together.ai\n","# Together AI — Serverless Inference & Fine-Tuning\n\nTogether AI is an AI cloud platform providing serverless inference on 200+ open-source models through an OpenAI-compatible API. It supports chat completions, embeddings, fine-tuning, image generation, and batch processing at `https:\u002F\u002Fapi.together.xyz\u002Fv1`.\n\n## When to Use Together AI\n\n**Use Together AI when:**\n- You need fast serverless inference on open-source models (Llama, DeepSeek, Qwen, Mistral)\n- You want an OpenAI-compatible API so you can swap providers with a single line change\n- You need to fine-tune open-source models without managing GPU infrastructure\n- You want cost-effective inference with pay-per-token pricing\n- You need function calling, JSON mode, or structured outputs from open-source models\n- You want batch processing at 50% lower cost for non-urgent workloads\n- You need embeddings or image generation alongside chat completions\n\n**Use alternatives instead:**\n\n| Need | Use Instead |\n|------|-------------|\n| Managed LoRA fine-tuning with training platform | **Tinker** |\n| Self-hosted inference with full control | **vLLM**, **TensorRT-LLM** |\n| Dedicated GPU instances | **Lambda Labs**, **RunPod** |\n| Serverless GPU with custom containers | **Modal** |\n| Multi-cloud cost optimization | **SkyPilot** |\n| Proprietary models (GPT-4o, Claude) | **OpenAI**, **Anthropic** directly |\n\n\n## Credential Setup\n\nCredentials are auto-injected by openscience when connected via the dashboard.\n\n```bash\n# Verify credentials\n[ -n \"$TOGETHER_API_KEY\" ] && echo \"TOGETHER_API_KEY set\" || echo \"NOT SET\"\n```\n\nIf not set: connect Together AI at https:\u002F\u002Fapp.syntheticsciences.ai -> Services, then restart openscience.\n\n## Quick Start\n\n### Install\n\n```python\npip install together openai\n```\n\n### Set API Key\n\n```python\nimport os\nos.environ[\"TOGETHER_API_KEY\"] = \"your-api-key\"\n\n# Or export in shell:\n# export TOGETHER_API_KEY=\"your-api-key\"\n```\n\nGet your API key from https:\u002F\u002Fapi.together.xyz\u002Fsettings\u002Fapi-keys\n\n### Basic Chat Completion\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Explain gradient descent in one paragraph.\"},\n    ],\n    max_tokens=256,\n    temperature=0.7,\n)\n\nprint(response.choices[0].message.content)\n```\n\n## Inference\n\n### Chat Completions\n\nThe primary endpoint for conversational AI. Supports system\u002Fuser\u002Fassistant messages, temperature, top_p, top_k, repetition_penalty, and stop sequences.\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.chat.completions.create(\n    model=\"deepseek-ai\u002FDeepSeek-V3\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are an expert ML researcher.\"},\n        {\"role\": \"user\", \"content\": \"Compare LoRA vs full fine-tuning.\"},\n    ],\n    max_tokens=512,\n    temperature=0.7,\n    top_p=0.9,\n    top_k=50,\n    repetition_penalty=1.1,\n    stop=[\"\u003C\u002Fs>\"],\n)\n\nprint(response.choices[0].message.content)\nprint(f\"Tokens used: {response.usage.total_tokens}\")\n```\n\n### Streaming\n\n```python\nfrom together import Together\n\nclient = Together()\n\nstream = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[{\"role\": \"user\", \"content\": \"Write a haiku about transformers.\"}],\n    max_tokens=128,\n    stream=True,\n)\n\nfor chunk in stream:\n    delta = chunk.choices[0].delta.content\n    if delta:\n        print(delta, end=\"\", flush=True)\nprint()\n```\n\n### Function Calling\n\nSupported on select models including Llama, DeepSeek, Qwen, and Mistral variants.\n\n```python\nfrom together import Together\nimport json\n\nclient = Together()\n\ntools = [\n    {\n        \"type\": \"function\",\n        \"function\": {\n            \"name\": \"get_weather\",\n            \"description\": \"Get the current weather for a location\",\n            \"parameters\": {\n                \"type\": \"object\",\n                \"properties\": {\n                    \"location\": {\n                        \"type\": \"string\",\n                        \"description\": \"City and state, e.g. San Francisco, CA\",\n                    },\n                    \"unit\": {\n                        \"type\": \"string\",\n                        \"enum\": [\"celsius\", \"fahrenheit\"],\n                    },\n                },\n                \"required\": [\"location\"],\n            },\n        },\n    }\n]\n\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"What's the weather in San Francisco?\"},\n    ],\n    tools=tools,\n    tool_choice=\"auto\",\n)\n\ntool_calls = response.choices[0].message.tool_calls\nif tool_calls:\n    call = tool_calls[0]\n    print(f\"Function: {call.function.name}\")\n    print(f\"Arguments: {call.function.arguments}\")\n```\n\n### JSON Mode (Structured Outputs)\n\nForce the model to return valid JSON conforming to a schema.\n\n```python\nimport json\nfrom together import Together\n\nclient = Together()\n\nschema = {\n    \"type\": \"object\",\n    \"properties\": {\n        \"name\": {\"type\": \"string\"},\n        \"age\": {\"type\": \"integer\"},\n        \"skills\": {\"type\": \"array\", \"items\": {\"type\": \"string\"}},\n    },\n    \"required\": [\"name\", \"age\", \"skills\"],\n}\n\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[\n        {\n            \"role\": \"system\",\n            \"content\": f\"Respond only in JSON matching this schema: {json.dumps(schema)}\",\n        },\n        {\"role\": \"user\", \"content\": \"Create a profile for a senior ML engineer.\"},\n    ],\n    response_format={\n        \"type\": \"json_object\",\n        \"schema\": schema,\n    },\n)\n\ndata = json.loads(response.choices[0].message.content)\nprint(json.dumps(data, indent=2))\n```\n\n### Vision Models\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-4-Scout-17B-16E-Instruct-VLM\",\n    messages=[\n        {\n            \"role\": \"user\",\n            \"content\": [\n                {\"type\": \"text\", \"text\": \"Describe this image in detail.\"},\n                {\n                    \"type\": \"image_url\",\n                    \"image_url\": {\"url\": \"https:\u002F\u002Fexample.com\u002Fimage.jpg\"},\n                },\n            ],\n        }\n    ],\n    max_tokens=512,\n)\n\nprint(response.choices[0].message.content)\n```\n\n## Fine-Tuning\n\nTogether AI supports both LoRA and full fine-tuning on a wide range of open-source models.\n\n### Data Format\n\nTraining data must be in JSONL format with chat-style messages:\n\n```jsonl\n{\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}, {\"role\": \"user\", \"content\": \"What is the capital of France?\"}, {\"role\": \"assistant\", \"content\": \"The capital of France is Paris.\"}]}\n{\"messages\": [{\"role\": \"user\", \"content\": \"Explain photosynthesis.\"}, {\"role\": \"assistant\", \"content\": \"Photosynthesis is the process by which plants convert sunlight, water, and carbon dioxide into glucose and oxygen.\"}]}\n```\n\nEach line is one training example. The `system` role is optional. The model learns to generate the `assistant` responses.\n\n### Upload Training Data\n\n```python\nfrom together import Together\n\nclient = Together()\n\n# Upload training file\nfile = client.files.upload(file=\"training_data.jsonl\")\nprint(f\"File ID: {file.id}\")\n```\n\n### Create Fine-Tuning Job\n\n```python\nfrom together import Together\n\nclient = Together()\n\n# Create LoRA fine-tuning job\njob = client.fine_tuning.create(\n    training_file=\"file-abc123\",\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    n_epochs=3,\n    learning_rate=1e-5,\n    batch_size=4,\n    lora=True,\n    lora_r=16,\n    lora_alpha=32,\n    lora_dropout=0.05,\n    suffix=\"my-custom-model\",\n)\n\nprint(f\"Job ID: {job.id}\")\nprint(f\"Status: {job.status}\")\n```\n\n### Monitor Fine-Tuning\n\n```python\nfrom together import Together\n\nclient = Together()\n\n# Check job status\njob = client.fine_tuning.retrieve(id=\"ft-abc123\")\nprint(f\"Status: {job.status}\")\n\n# List all jobs\njobs = client.fine_tuning.list()\nfor j in jobs:\n    print(f\"{j.id}: {j.status}\")\n\n# List events (training logs)\nevents = client.fine_tuning.list_events(id=\"ft-abc123\")\nfor event in events:\n    print(event)\n\n# Cancel a job\nclient.fine_tuning.cancel(id=\"ft-abc123\")\n```\n\n### CLI Fine-Tuning\n\n```bash\n# Install CLI\npip install --upgrade together\n\n# Upload data\ntogether files upload training_data.jsonl\n\n# Create fine-tuning job\ntogether fine-tuning create \\\n    --training-file file-abc123 \\\n    -m meta-llama\u002FMeta-Llama-3.1-8B-Instruct-Reference\n\n# Check status\ntogether fine-tuning status ft-abc123\n\n# List checkpoints\ntogether fine-tuning list-checkpoints ft-abc123\n\n# Download fine-tuned model\ntogether fine-tuning download --ft-id ft-abc123\n```\n\n### Supported Fine-Tuning Models (Selection)\n\n| Model | LoRA | Full |\n|-------|------|------|\n| meta-llama\u002FMeta-Llama-3.1-8B-Instruct-Reference | Yes | Yes |\n| meta-llama\u002FLlama-3.3-70B-Instruct-Reference | Yes | Yes |\n| meta-llama\u002FLlama-4-Scout-17B-16E-Instruct | Yes | No |\n| deepseek-ai\u002FDeepSeek-V3 | Yes | No |\n| deepseek-ai\u002FDeepSeek-R1 | Yes | No |\n| Qwen\u002FQwen3-8B | Yes | Yes |\n| Qwen\u002FQwen3-32B | Yes | Yes |\n| Qwen\u002FQwen3-235B-A22B | Yes | No |\n| google\u002Fgemma-3-27b-it | Yes | Yes |\n| google\u002Fgemma-3-4b-it | Yes | Yes |\n\nSee the full list at https:\u002F\u002Fdocs.together.ai\u002Fdocs\u002Ffine-tuning-models\n\n## Embeddings\n\n### Generate Embeddings\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.embeddings.create(\n    model=\"BAAI\u002Fbge-large-en-v1.5\",\n    input=\"What is the meaning of life?\",\n)\n\nembedding = response.data[0].embedding\nprint(f\"Dimensions: {len(embedding)}\")\nprint(f\"First 5 values: {embedding[:5]}\")\n```\n\n### Batch Embeddings\n\n```python\nfrom together import Together\n\nclient = Together()\n\ntexts = [\n    \"Machine learning is a subset of AI.\",\n    \"Deep learning uses neural networks.\",\n    \"Transformers revolutionized NLP.\",\n]\n\nresponse = client.embeddings.create(\n    model=\"BAAI\u002Fbge-large-en-v1.5\",\n    input=texts,\n)\n\nfor i, item in enumerate(response.data):\n    print(f\"Text {i}: {len(item.embedding)} dimensions\")\n```\n\n### Available Embedding Models\n\n| Model ID | Dimensions | Best For |\n|----------|-----------|----------|\n| `BAAI\u002Fbge-large-en-v1.5` | 1024 | General-purpose English retrieval |\n| `BAAI\u002Fbge-base-en-v1.5` | 768 | Balanced performance and cost |\n| `WhereIsAI\u002FUAE-Large-V1` | 1024 | High-accuracy retrieval |\n| `togethercomputer\u002Fm2-bert-80M-8k-retrieval` | 768 | Long-context (8k tokens) retrieval |\n\n## Image Generation\n\nTogether AI hosts FLUX models from Black Forest Labs for high-quality image generation.\n\n### Generate Images\n\n```python\nfrom together import Together\n\nclient = Together()\n\nresponse = client.images.generate(\n    model=\"black-forest-labs\u002FFLUX.1-schnell\",\n    prompt=\"A photorealistic mountain landscape at sunset with a lake reflection\",\n    steps=4,\n    n=1,\n    width=1024,\n    height=1024,\n)\n\n# Response contains URL or base64 image data\nprint(response.data[0].url)\n```\n\n### Available Image Models\n\n| Model ID | Type | Notes |\n|----------|------|-------|\n| `black-forest-labs\u002FFLUX.1-schnell` | Fast generation | Fastest, lower step count (4 steps) |\n| `black-forest-labs\u002FFLUX.1-dev` | Development | LoRA support for custom styles |\n| `black-forest-labs\u002FFLUX.1.1-pro` | Premium | Highest quality, best prompt adherence |\n\n### Image with OpenAI SDK\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI(\n    api_key=os.environ[\"TOGETHER_API_KEY\"],\n    base_url=\"https:\u002F\u002Fapi.together.xyz\u002Fv1\",\n)\n\nresponse = client.images.generate(\n    model=\"black-forest-labs\u002FFLUX.1-schnell\",\n    prompt=\"A cyberpunk cityscape at night\",\n    n=1,\n)\n\nprint(response.data[0].url)\n```\n\n## Batch Inference\n\nBatch API processes large volumes of requests asynchronously at 50% lower cost with a 24-hour turnaround.\n\n### Input File Format\n\nCreate a JSONL file where each line is a request:\n\n```jsonl\n{\"custom_id\": \"request-1\", \"body\": {\"model\": \"deepseek-ai\u002FDeepSeek-V3\", \"messages\": [{\"role\": \"user\", \"content\": \"What is machine learning?\"}], \"max_tokens\": 200}}\n{\"custom_id\": \"request-2\", \"body\": {\"model\": \"deepseek-ai\u002FDeepSeek-V3\", \"messages\": [{\"role\": \"user\", \"content\": \"Explain gradient descent.\"}], \"max_tokens\": 200}}\n{\"custom_id\": \"request-3\", \"body\": {\"model\": \"deepseek-ai\u002FDeepSeek-V3\", \"messages\": [{\"role\": \"user\", \"content\": \"What are transformers?\"}], \"max_tokens\": 200}}\n```\n\n### Submit Batch Job\n\n```python\nfrom together import Together\n\nclient = Together()\n\n# 1. Upload the batch file\nbatch_file = client.files.upload(\n    file=\"batch_requests.jsonl\",\n    purpose=\"batch-api\",\n)\nprint(f\"File ID: {batch_file.id}\")\n\n# 2. Create the batch job\nbatch = client.batches.create_batch(\n    file_id=batch_file.id,\n    endpoint=\"\u002Fv1\u002Fchat\u002Fcompletions\",\n)\nprint(f\"Batch ID: {batch.id}\")\n\n# 3. Monitor status\nstatus = client.batches.get_batch(batch.id)\nprint(f\"Status: {status.status}\")\n\n# 4. Download results when completed\nif status.status == \"COMPLETED\":\n    results = client.files.retrieve_content(\n        id=status.output_file_id,\n    )\n    print(results)\n```\n\n### List Batches\n\n```python\nfrom together import Together\n\nclient = Together()\n\nbatches = client.batches.list_batches()\nfor b in batches:\n    print(f\"{b.id}: {b.status}\")\n```\n\n## Model Selection\n\n### Chat \u002F Instruct Models\n\n| Model ID | Params | Input $\u002FM | Output $\u002FM | Context | Best For |\n|----------|--------|-----------|------------|---------|----------|\n| `meta-llama\u002FMeta-Llama-3.1-8B-Instruct-Reference` | 8B | $0.18 | $0.18 | 131k | Fast, cheap general tasks |\n| `meta-llama\u002FLlama-3.3-70B-Instruct-Reference` | 70B | $0.88 | $0.88 | 131k | High-quality general purpose |\n| `meta-llama\u002FLlama-4-Maverick-17B-128E-Instruct` | 400B MoE | $0.27 | $0.85 | 1M | Cost-effective large model |\n| `deepseek-ai\u002FDeepSeek-V3` | 671B MoE | $1.25 | $1.25 | 128k | Top-tier reasoning and code |\n| `deepseek-ai\u002FDeepSeek-R1` | 671B MoE | $3.00 | $7.00 | 128k | Complex reasoning with CoT |\n| `Qwen\u002FQwen3-Next-80B-A3B-Instruct` | 80B MoE | $0.15 | $1.50 | 128k | Ultra-cheap MoE inference |\n| `Qwen\u002FQwen3-235B-A22B` | 235B MoE | $0.50 | $1.50 | 128k | Powerful open-weight MoE |\n| `mistralai\u002FMixtral-8x7B-Instruct-v0.1` | 46B MoE | $0.60 | $0.60 | 32k | Balanced MoE model |\n| `Qwen\u002FQwen3-Coder-480B-A35B-Instruct` | 480B MoE | $0.60 | $1.80 | 256k | Code generation and review |\n| `google\u002Fgemma-3-27b-it` | 27B | $0.30 | $0.30 | 128k | Google's efficient model |\n\n### Reasoning Models\n\n| Model ID | Input $\u002FM | Output $\u002FM | Notes |\n|----------|-----------|------------|-------|\n| `deepseek-ai\u002FDeepSeek-R1` | $3.00 | $7.00 | Chain-of-thought reasoning |\n| `deepseek-ai\u002FDeepSeek-R1-0528` | $3.00 | $7.00 | Updated R1 variant |\n| `Qwen\u002FQwen3-Next-80B-A3B-Thinking` | $0.15 | $1.50 | MoE reasoning, very cheap |\n\n### Code Models\n\n| Model ID | Input $\u002FM | Output $\u002FM | Notes |\n|----------|-----------|------------|-------|\n| `Qwen\u002FQwen3-Coder-30B-A3B-Instruct` | $0.15 | $1.50 | Fast code MoE |\n| `Qwen\u002FQwen3-Coder-480B-A35B-Instruct` | $0.60 | $1.80 | Largest code model |\n\nPricing is approximate and subject to change. Check https:\u002F\u002Fwww.together.ai\u002Fpricing for current rates.\n\n## OpenAI Compatibility\n\nTogether AI is fully compatible with the OpenAI Python SDK. Change two lines to switch from OpenAI to Together AI.\n\n### Using OpenAI SDK\n\n```python\nfrom openai import OpenAI\nimport os\n\n# Just change the API key and base_url\nclient = OpenAI(\n    api_key=os.environ[\"TOGETHER_API_KEY\"],\n    base_url=\"https:\u002F\u002Fapi.together.xyz\u002Fv1\",\n)\n\n# Everything else is identical to OpenAI usage\nresponse = client.chat.completions.create(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Hello!\"},\n    ],\n    max_tokens=256,\n)\n\nprint(response.choices[0].message.content)\n```\n\n### What Works with OpenAI SDK\n\n| Feature | Supported |\n|---------|-----------|\n| `chat.completions.create` | Yes |\n| Streaming responses | Yes |\n| Function calling \u002F tools | Yes |\n| JSON mode \u002F structured outputs | Yes |\n| Vision (multimodal) | Yes |\n| `embeddings.create` | Yes |\n| `images.generate` | Yes |\n| `fine_tuning.jobs.create` | Yes |\n| `models.list` | Yes |\n| Async client | Yes |\n| `.with_raw_response` | Yes |\n| `.with_streaming_response` | Yes |\n\n### LangChain Integration\n\n```python\nfrom langchain_openai import ChatOpenAI\n\nllm = ChatOpenAI(\n    model=\"meta-llama\u002FLlama-3.3-70B-Instruct-Reference\",\n    openai_api_key=os.environ[\"TOGETHER_API_KEY\"],\n    openai_api_base=\"https:\u002F\u002Fapi.together.xyz\u002Fv1\",\n)\n\nresponse = llm.invoke(\"What is the meaning of life?\")\nprint(response.content)\n```\n\n## CLI Reference\n\nThe `together` CLI provides direct access from the terminal.\n\n```bash\n# Install\npip install --upgrade together\n\n# Set API key\nexport TOGETHER_API_KEY=\"your-api-key\"\n\n# Chat completion\ntogether chat.completions \\\n    --message \"system\" \"You are helpful.\" \\\n    --message \"user\" \"What is PyTorch?\" \\\n    --model meta-llama\u002FLlama-3.3-70B-Instruct-Reference\n\n# List models\ntogether models list\n\n# Image generation\ntogether images generate \\\n    \"A futuristic city at sunset\" \\\n    --model black-forest-labs\u002FFLUX.1-schnell \\\n    --n 1\n\n# File operations\ntogether files upload training_data.jsonl\ntogether files list\ntogether files retrieve file-abc123\ntogether files delete file-abc123\n\n# Fine-tuning\ntogether fine-tuning create \\\n    --training-file file-abc123 \\\n    -m meta-llama\u002FMeta-Llama-3.1-8B-Instruct-Reference\ntogether fine-tuning list\ntogether fine-tuning status ft-abc123\ntogether fine-tuning list-events ft-abc123\ntogether fine-tuning list-checkpoints ft-abc123\ntogether fine-tuning download --ft-id ft-abc123\ntogether fine-tuning cancel ft-abc123\n```\n\n## Cost Optimization\n\n### 1. Use MoE Models\n\nMixture-of-Experts models activate only a fraction of parameters per token, offering better price-to-performance:\n\n| Model | Active Params | Price |\n|-------|--------------|-------|\n| Qwen3-Next-80B-A3B | 3B active of 80B | $0.15\u002FM input |\n| Llama-4-Maverick | 17B active of 400B | $0.27\u002FM input |\n| DeepSeek-V3 | ~37B active of 671B | $1.25\u002FM input |\n\n### 2. Use Batch API\n\nSubmit non-urgent workloads via the batch API for 50% cost reduction. Ideal for evaluations, dataset generation, and bulk classification.\n\n### 3. Use JSON Mode for Structured Output\n\nAvoid post-processing errors and retry loops by constraining output format upfront.\n\n### 4. Right-Size Your Model\n\n- **Simple classification\u002Fextraction**: 8B models ($0.18\u002FM)\n- **General chat\u002Finstruction**: 70B models ($0.88\u002FM)\n- **Complex reasoning\u002Fcode**: DeepSeek-V3 ($1.25\u002FM) or R1 ($3.00\u002FM)\n- **Cost-sensitive high volume**: MoE models like Qwen3-Next ($0.15\u002FM)\n\n### 5. Minimize Max Tokens\n\nSet `max_tokens` to the minimum needed. You pay for output tokens generated, not the max_tokens budget.\n\n### 6. Use Streaming for Long Outputs\n\nStreaming does not cost more but gives faster time-to-first-token and lets you abort early if the output goes off track.\n\n## Common Issues\n\n| Problem | Solution |\n|---------|----------|\n| `401 Unauthorized` | Check `TOGETHER_API_KEY` is set and valid |\n| `429 Rate Limited` | Implement exponential backoff; upgrade plan for higher limits |\n| `Model not found` | Verify model ID at https:\u002F\u002Fdocs.together.ai\u002Fdocs\u002Fserverless-models |\n| JSON mode returns invalid JSON | Include the schema in the system prompt alongside `response_format` |\n| Function calling not working | Use supported models (Llama 3.x, DeepSeek, Qwen3, Mistral) |\n| Fine-tuning job stuck | Check data format (must be valid JSONL with `messages` array) |\n| Batch job failed | Verify JSONL format has `custom_id` and `body` fields per line |\n| Slow response times | Try Turbo\u002FLite model variants or reduce `max_tokens` |\n| Embedding dimensions mismatch | Different models produce different dimensions (768 or 1024) |\n| Image generation timeout | Reduce `steps` parameter; use FLUX.1-schnell for fastest results |\n\n## Resources\n\n- **Documentation**: https:\u002F\u002Fdocs.together.ai\n- **API Reference**: https:\u002F\u002Fdocs.together.ai\u002Freference\n- **Pricing**: https:\u002F\u002Fwww.together.ai\u002Fpricing\n- **Dashboard**: https:\u002F\u002Fapi.together.xyz\n- **Model Catalog**: https:\u002F\u002Fdocs.together.ai\u002Fdocs\u002Fserverless-models\n- **Fine-Tuning Guide**: https:\u002F\u002Fdocs.together.ai\u002Fdocs\u002Ffine-tuning-quickstart\n- **Python SDK**: https:\u002F\u002Fgithub.com\u002Ftogethercomputer\u002Ftogether-python\n- **TypeScript SDK**: https:\u002F\u002Fgithub.com\u002Ftogethercomputer\u002Ftogether-typescript\n- **Cookbook (Examples)**: https:\u002F\u002Fgithub.com\u002Ftogethercomputer\u002Ftogether-cookbook\n- **Status Page**: https:\u002F\u002Fstatus.together.ai\n",{"name":5,"tags":44,"author":53,"license":15,"version":54,"category":55,"description":7,"dependencies":56},[45,46,47,48,49,50,51,52],"Inference","Together AI","Fine-Tuning","Embeddings","Serverless","OpenAI-Compatible","Batch","Image Generation","Synthetic Sciences","1.0.0","cloud-compute",[57,36],"together","main","4aa39efd1cdab0b4657ecee16c92a92011a5b10f","openscience\u002Fbackend\u002Fcli\u002Fskills\u002Fcloud-compute\u002Ftogether-ai","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub","https:\u002F\u002Fgithub.com\u002Ffadrienne","2026-10-28 00:43:09",{"source":8,"skillName":5,"commands":65,"prompt":75,"zipAvailable":76},[66,69,72],{"tool":67,"command":68},"npx","npx skills add fadrienne\u002FMyGitHub --skill together-ai-inference",{"tool":70,"command":71},"bunx","bunx skills add fadrienne\u002FMyGitHub --skill together-ai-inference",{"tool":73,"command":74},"pnpm","pnpm dlx skills add fadrienne\u002FMyGitHub --skill together-ai-inference","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fopenscience\u002Fbackend\u002Fcli\u002Fskills\u002Fcloud-compute\u002Ftogether-ai\u002FSKILL.md",true,[],[79,105,129,155,180,200],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":83,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":104},"01M6XF367QJAN2RNPJWZ3SENGD","hallmark","Anti-AI-slop design skill for greenfield pages, audits, redesigns, and design extraction from URLs or screenshots. Use when the user asks to build a new app or landing page, wants to redesign something, invokes Hallmark by name, or uses audit\u002Fredesign\u002Fstudy.","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fhallmark\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fhallmark\u002FSKILL.md",[],[81,87,88,89,90,23,91,92,93,94,95,96,97,98,99,29,100,101,102,103],"app","slop","Anti-AI","design","audit","redesign","screenshots","by name","for","page","study","landing","pages","anti-ai-slop","build","name","landing page","2026-11-10 22:39:42",{"skillNo":106,"name":107,"nameZh":6,"description":108,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":109,"licenseFileUrl":110,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":104},"01M6XAFXNBF8DXAXJ4ZMPQ82M8","brand-guidelines","Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fanthropic-skills\u002Fskills\u002Fbrand-guidelines\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fanthropic-skills\u002Fskills\u002Fbrand-guidelines\u002FSKILL.md",[],[114,115,116,117,118,119,90,29,23,120,121,122,123,124,125,126,127,128],"brand","guidelines","brand guidelines","standards","official","company","apply","sort","visual","artifact","style","look","typography","it","formatting",{"skillNo":130,"name":131,"nameZh":6,"description":132,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":109,"licenseFileUrl":133,"sourceHtmlUrl":134,"categories":135,"keywords":136,"publishedAt":104},"01M6XAFSEYZJ2TNR02EQG7Y7ZZ","algorithmic-art","Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fanthropic-skills\u002Fskills\u002Falgorithmic-art\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fanthropic-skills\u002Fskills\u002Falgorithmic-art\u002FSKILL.md",[],[137,138,139,140,141,142,29,143,23,144,145,146,147,148,149,150,151,152,153,154],"Art","algorithmic art","algorithmic","copyright","exploration","generative","Existing","generative art","code","interactive","users","with","create","work","request","systems","flow","fields",{"skillNo":156,"name":157,"nameZh":6,"description":158,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":159,"categories":160,"keywords":161,"publishedAt":39},"01M7167B28PK20HP7R7ZED2DY0","statistical-power","Sample size calculation, power analysis, and effect size conversion for scientific studies. Use BEFORE data collection (a priori) to determine required N, or after (post-hoc) to compute achieved power. Covers parametric tests (t-test, ANOVA, chi-square, proportions, correlation, regression), simulation-based power for complex\u002Fclustered\u002Fnested designs, and power curves. Use this skill when someone asks 'how many samples do I need', 'what is my power', 'what effect size can I detect', or any variant. Pairs with \u002Fexperimental-design (choose design first, then compute power) and \u002Fstatistical-analysis (analyze data after collection).","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fscientific-agent-skills\u002Fskills\u002Fstatistical-power\u002FSKILL.md",[],[162,163,164,165,166,167,90,168,23,169,170,171,172,173,174,175,176,177,178,179],"power","statistical power","effect","scipy","regression","choose","uv","Bash","collection","analysis","calculation","ANOVA","conversion","analyze","t-test","chi-square","simulation","sample",{"skillNo":181,"name":182,"nameZh":6,"description":183,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":184,"categories":185,"keywords":186,"publishedAt":39},"01M71677EBCM8EPCE9BZCK8505","statistical-analysis","Guided statistical analysis with test selection and reporting. Use when you need help choosing appropriate tests for your data, assumption checking, power analysis, and APA-formatted results. Best for academic research reporting, test selection guidance. For implementing specific models programmatically use statsmodels.","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fscientific-agent-skills\u002Fskills\u002Fstatistical-analysis\u002FSKILL.md",[],[171,187,162,188,189,190,23,26,191,192,95,193,29,148,194,195,196,197,198,199],"statistical analysis","academic research","implementing","selection","reporting","data","tests","test","research","results","statsmodels","models","help",{"skillNo":201,"name":202,"nameZh":6,"description":203,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":204,"categories":205,"keywords":206,"publishedAt":39},"01M71673R93XAHFH81DBNVNG7H","scientific-writing","Core skill for the deep research and writing tool. Write scientific manuscripts in full paragraphs (never bullet points). Use two-stage process with (1) section outlines with key points using research-lookup then (2) convert to flowing prose. IMRAD structure, citations (APA\u002FAMA\u002FVancouver), figures\u002Ftables, reporting guidelines (CONSORT\u002FSTROBE\u002FPRISMA), for research papers and journal submissions.","https:\u002F\u002Fgithub.com\u002Ffadrienne\u002FMyGitHub\u002Fblob\u002Fmain\u002Fscientific-agent-skills\u002Fskills\u002Fscientific-writing\u002FSKILL.md",[],[207,208,209,210,211,212,213,214,215,216,169,32,217,218,219,220,221,222,191,223],"writing","scientific","scientific writing","Citations","deep","deep research","never","papers","journal","false","prisma","structure","openrouter","Outlines","core skill","read","features"]