Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:BerriAI Litellm Fine Tuning Job Operations

From Leeroopedia
Revision as of 12:09, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/BerriAI_Litellm_Fine_Tuning_Job_Operations.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources Domains Last Updated
BerriAI/litellm Fine-Tuning, Job Management, API Integration 2026-02-15

Overview

Concrete tools for listing, retrieving, and cancelling fine-tuning jobs across LLM providers provided by LiteLLM.

Description

LiteLLM provides three complementary functions for managing the lifecycle of fine-tuning jobs after creation: list_fine_tuning_jobs retrieves a paginated list of all fine-tuning jobs in an organization; retrieve_fine_tuning_job fetches detailed status and metadata for a single job by its identifier; and cancel_fine_tuning_job immediately terminates a running or queued job. Each function supports OpenAI and Azure OpenAI providers (with list and cancel also supporting Vertex AI for creation but routing through OpenAI/Azure for listing and retrieval). All three functions have both synchronous and asynchronous variants and follow the same credential resolution, timeout management, and provider routing patterns used throughout LiteLLM.

Usage

Use these functions when:

  • Polling for the completion status of a previously created fine-tuning job.
  • Building dashboards or monitoring tools that display all fine-tuning jobs.
  • Implementing automated pipelines that wait for job completion before deploying models.
  • Cancelling jobs that are no longer needed or were started with incorrect parameters.

Code Reference

Source Location

litellm/fine_tuning/main.py (lines 326-762)

Signature

# Cancel a fine-tuning job (sync)
def cancel_fine_tuning_job(
    fine_tuning_job_id: str,
    custom_llm_provider: Literal["openai", "azure", "vertex_ai"] = "openai",
    extra_headers: Optional[Dict[str, str]] = None,
    extra_body: Optional[Dict[str, str]] = None,
    **kwargs,
) -> Union[LiteLLMFineTuningJob, Coroutine[Any, Any, LiteLLMFineTuningJob]]:

# List fine-tuning jobs (async)
async def alist_fine_tuning_jobs(
    after: Optional[str] = None,
    limit: Optional[int] = None,
    custom_llm_provider: Literal["openai", "azure", "vertex_ai"] = "openai",
    extra_headers: Optional[Dict[str, str]] = None,
    extra_body: Optional[Dict[str, str]] = None,
    **kwargs,
):

# List fine-tuning jobs (sync)
def list_fine_tuning_jobs(
    after: Optional[str] = None,
    limit: Optional[int] = None,
    custom_llm_provider: Literal["openai", "azure", "vertex_ai"] = "openai",
    extra_headers: Optional[Dict[str, str]] = None,
    extra_body: Optional[Dict[str, str]] = None,
    **kwargs,
):

# Retrieve a fine-tuning job (async)
async def aretrieve_fine_tuning_job(
    fine_tuning_job_id: str,
    custom_llm_provider: Literal["openai", "azure", "vertex_ai"] = "openai",
    extra_headers: Optional[Dict[str, str]] = None,
    extra_body: Optional[Dict[str, str]] = None,
    **kwargs,
) -> LiteLLMFineTuningJob:

# Retrieve a fine-tuning job (sync)
def retrieve_fine_tuning_job(
    fine_tuning_job_id: str,
    custom_llm_provider: Literal["openai", "azure", "vertex_ai"] = "openai",
    extra_headers: Optional[Dict[str, str]] = None,
    extra_body: Optional[Dict[str, str]] = None,
    **kwargs,
) -> Union[LiteLLMFineTuningJob, Coroutine[Any, Any, LiteLLMFineTuningJob]]:

Import

from litellm.fine_tuning.main import (
    list_fine_tuning_jobs,
    alist_fine_tuning_jobs,
    retrieve_fine_tuning_job,
    aretrieve_fine_tuning_job,
    cancel_fine_tuning_job,
)

I/O Contract

Inputs (list_fine_tuning_jobs)

Parameter Type Required Description
after Optional[str] No Identifier for the last job from the previous pagination request. Used as a cursor for forward pagination.
limit Optional[int] No Number of fine-tuning jobs to retrieve per page. Defaults to 20 on most providers.
custom_llm_provider Literal["openai", "azure", "vertex_ai"] No The LLM provider to query. Defaults to "openai".
extra_headers Optional[Dict[str, str]] No Additional HTTP headers.
extra_body Optional[Dict[str, str]] No Additional request body fields.
**kwargs various No Additional parameters including api_key, api_base, api_version, timeout.

Inputs (retrieve_fine_tuning_job)

Parameter Type Required Description
fine_tuning_job_id str Yes The unique identifier of the fine-tuning job to retrieve.
custom_llm_provider Literal["openai", "azure", "vertex_ai"] No The LLM provider. Defaults to "openai".
extra_headers Optional[Dict[str, str]] No Additional HTTP headers.
extra_body Optional[Dict[str, str]] No Additional request body fields.
**kwargs various No Additional parameters including api_key, api_base, timeout.

Inputs (cancel_fine_tuning_job)

Parameter Type Required Description
fine_tuning_job_id str Yes The unique identifier of the fine-tuning job to cancel.
custom_llm_provider Literal["openai", "azure", "vertex_ai"] No The LLM provider. Defaults to "openai".
extra_headers Optional[Dict[str, str]] No Additional HTTP headers.
extra_body Optional[Dict[str, str]] No Additional request body fields.
**kwargs various No Additional parameters including api_key, api_base, timeout.

Outputs

Function Return Type Description
list_fine_tuning_jobs List of fine-tuning job objects A paginated list of fine-tuning jobs for the organization, each containing id, status, model, created_at, and other metadata.
retrieve_fine_tuning_job LiteLLMFineTuningJob A single fine-tuning job object with full details including status, fine_tuned_model (if succeeded), error (if failed), and hyperparameters.
cancel_fine_tuning_job LiteLLMFineTuningJob The cancelled fine-tuning job object with updated status reflecting the cancellation.

Usage Examples

List all fine-tuning jobs

from litellm.fine_tuning.main import list_fine_tuning_jobs

# List the first 10 jobs
jobs = list_fine_tuning_jobs(
    limit=10,
    custom_llm_provider="openai",
)

for job in jobs.data:
    print(f"Job {job.id}: status={job.status}, model={job.model}")

Retrieve a specific job status

from litellm.fine_tuning.main import retrieve_fine_tuning_job

job = retrieve_fine_tuning_job(
    fine_tuning_job_id="ftjob-abc123",
    custom_llm_provider="openai",
)

print(f"Status: {job.status}")
print(f"Model: {job.model}")

if job.status == "succeeded":
    print(f"Fine-tuned model: {job.fine_tuned_model}")
elif job.status == "failed" and job.error:
    print(f"Error: {job.error}")

Poll until job completion

import time
from litellm.fine_tuning.main import retrieve_fine_tuning_job

def wait_for_job(job_id, provider="openai", poll_interval=60, max_wait=7200):
    elapsed = 0
    while elapsed < max_wait:
        job = retrieve_fine_tuning_job(
            fine_tuning_job_id=job_id,
            custom_llm_provider=provider,
        )
        if job.status in ["succeeded", "failed", "cancelled"]:
            return job
        time.sleep(poll_interval)
        elapsed += poll_interval
    raise TimeoutError(f"Job {job_id} did not complete within {max_wait} seconds")

completed_job = wait_for_job("ftjob-abc123")
print(f"Final status: {completed_job.status}")

Cancel a running job

from litellm.fine_tuning.main import cancel_fine_tuning_job

cancelled_job = cancel_fine_tuning_job(
    fine_tuning_job_id="ftjob-abc123",
    custom_llm_provider="openai",
)

print(f"Job {cancelled_job.id} status: {cancelled_job.status}")

Async retrieve with Azure

import asyncio
from litellm.fine_tuning.main import aretrieve_fine_tuning_job

async def check_job_status():
    job = await aretrieve_fine_tuning_job(
        fine_tuning_job_id="ftjob-azure-456",
        custom_llm_provider="azure",
        api_base="https://my-resource.openai.azure.com/",
        api_key="my-azure-api-key",
        api_version="2024-02-01",
    )
    return job

result = asyncio.run(check_job_status())
print(f"Status: {result.status}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment