Skip to main content

A set of utils to make Together AI API easier to use. Implements the utils for the model fine-tuning and simplified endpoint fetching. Uses the official Together AI API and builds up on it (https://github.com/togethercomputer/together-python).

Project description

Together AI API Helper

A Python package that provides high-level utilities for working with Together AI's API, making endpoint management and fine-tuning operations simpler and more robust.

Features

🚀 Endpoint Management

  • Automatic endpoint provisioning and configuration
  • State monitoring and health checks
  • Hardware configuration management

🎯 Fine-Tuning Operations

  • Automated fine-tuning job lifecycle management
  • Real-time job monitoring with event streaming
  • Training file validation and upload
  • Automatic Hugging Face repository creation

Installation

Install the package from PyPI:

uv add together-ai-api-helper

Requirements

  • Python ≥ 3.13
  • Together AI API key
  • Hugging Face token (if you want to upload the fine-tuned models)

Setup

1. API tokens

Set your API keys as environment variables. (Note that the HF_TOKEN is optional and is only needed if you want to automatically upload the trained model to HF):

export TOGETHER_API_KEY="your-api-key-here"
export HF_TOKEN="your-hf-token-here"

Usage

Endpoint Management

from together_ai_api_helper.endpoints import EndpointClient, EndpointConfig, GenerateConfig

# Initialize the client
client = EndpointClient()

# Configure your endpoint
config = EndpointConfig(
    model_name="mistralai/Mistral-7B-Instruct-v0.1",
    display_name="My Mistral Endpoint",
    # Uses cheapest compatible hardware by default
)

# Get or create an endpoint
endpoint_name, endpoint_id = client.get_endpoint_for_model(config)
print(f"Endpoint ready: {endpoint_name} ({endpoint_id})")

Fine-Tuning

from together_ai_api_helper.training import TrainingClient, TrainingConfig

# Initialize the training client
client = TrainingClient()

# Configure your training job
config = TrainingConfig(
    model="mistralai/Mistral-7B-Instruct-v0.1",
    training_file="path/to/your/training_data.jsonl",
    suffix="my-custom-model",
    n_epochs=3,
    learning_rate=1e-5,
    **other_together_ai_params
)

# Train the model (this will monitor progress automatically)
model_name = client.start_job(config)

Logging

All operations are logged with detailed information. Logs include:

  • Endpoint state changes
  • Training progress and events
  • Error messages and debugging information
  • API interactions and timing

Log files are created automatically (can change the file paths):

  • endpoints.log for endpoint operations
  • training.log for fine-tuning operations

API Reference

EndpointClient Methods

  • get_endpoint_for_model(config) - Get or create an endpoint
  • list_active_endpoints() - List all active endpoints
  • list_inactive_endpoints() - List all inactive endpoints
  • restart_endpoint(endpoint_id) - Restart a stopped endpoint
  • stop_endpoint(endpoint_id) - Stop a running endpoint
  • delete_endpoint(endpoint_id) - Delete an endpoint

TrainingClient Methods

  • start_job(config) - Start and monitor a fine-tuning job
  • monitor_job(job_id) - Monitor an existing job
  • cancel_job(job_id) - Cancel a running job

Contributing

This package builds on top of the official Together Python SDK.

For development use the dev extra dependencies:

uv sync --extra dev

Note that the linting and type checking will run automatically in pre-commit.

License

MIT License

Support

For issues and questions:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

together_ai_api_helper-0.1.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

together_ai_api_helper-0.1.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file together_ai_api_helper-0.1.1.tar.gz.

File metadata

File hashes

Hashes for together_ai_api_helper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 50deb40ced918240f9afdcfaa4fddc70f8e47eb911ab388779a882f90ec4c316
MD5 f1caccf43ea51cbc59986f0187c9b02c
BLAKE2b-256 8f52be94e02a1ce5cacc919a5568e773927c7cc74dee160803fa552a45f5bf38

See more details on using hashes here.

File details

Details for the file together_ai_api_helper-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for together_ai_api_helper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 69de80b7f438468b9b463b70b9206ec61d36c9c4cb10ab216d91d2530ffc712c
MD5 1a2adc6a12cabce72777b4b2bd3ceff2
BLAKE2b-256 d3e513c278e383fe776c7847a616419af704165b41dddd7f59367b441b290325

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page