Implementation:Openai Openai node FineTuning Jobs Resource
| Knowledge Sources | |
|---|---|
| Domains | SDK, Fine-Tuning, Model Training |
| Last Updated | 2026-02-15 12:00 GMT |
Overview
The Jobs resource class provides methods for creating, managing, and monitoring fine-tuning jobs through the OpenAI API.
Description
The Jobs class extends APIResource and serves as the primary interface for the OpenAI fine-tuning jobs endpoint (/fine_tuning/jobs). It enables developers to create fine-tuning jobs that train custom models from uploaded datasets, retrieve job status, list all jobs in an organization, cancel running jobs, and monitor job events.
The resource supports three fine-tuning methods: supervised, DPO (Direct Preference Optimization), and reinforcement. Each method has its own configuration options accessible through the method parameter. The class also provides lifecycle management with pause and resume methods for controlling running jobs. Pagination is handled through cursor-based pagination via CursorPage.
A nested checkpoints sub-resource is available for accessing fine-tuning job checkpoints. The class defines comprehensive TypeScript types for job objects, events, parameters, and Weights & Biases integration.
Usage
Use this resource when you need to fine-tune OpenAI models on custom training data. This includes creating new fine-tuning jobs with specific model and dataset configurations, monitoring job progress through events, managing job lifecycle (pause, resume, cancel), and listing historical jobs for your organization.
Code Reference
Source Location
- Repository: openai-node
- File: src/resources/fine-tuning/jobs/jobs.ts
Signature
export class Jobs extends APIResource {
checkpoints: CheckpointsAPI.Checkpoints;
create(body: JobCreateParams, options?: RequestOptions): APIPromise<FineTuningJob>;
retrieve(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob>;
list(query?: JobListParams | null, options?: RequestOptions): PagePromise<FineTuningJobsPage, FineTuningJob>;
cancel(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob>;
listEvents(fineTuningJobID: string, query?: JobListEventsParams | null, options?: RequestOptions): PagePromise<FineTuningJobEventsPage, FineTuningJobEvent>;
pause(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob>;
resume(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob>;
}
Import
import OpenAI from 'openai';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | 'babbage-002' | 'davinci-002' | 'gpt-3.5-turbo' | 'gpt-4o-mini' | Yes | The name of the model to fine-tune |
| training_file | string |
Yes | The ID of an uploaded JSONL file containing training data |
| validation_file | null | No | The ID of an uploaded file containing validation data |
| method | JobCreateParams.Method |
No | Fine-tuning method: supervised, dpo, or reinforcement |
| hyperparameters | JobCreateParams.Hyperparameters |
No | Deprecated in favor of method; controls batch_size, learning_rate_multiplier, n_epochs |
| suffix | null | No | A string up to 64 characters added to the fine-tuned model name |
| seed | null | No | Controls reproducibility of the job |
| metadata | null | No | Set of 16 key-value pairs for storing additional information |
| integrations | null | No | Integrations to enable (currently only Weights and Biases) |
Outputs
| Name | Type | Description |
|---|---|---|
| id | string |
The object identifier for the fine-tuning job |
| status | 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled' | Current status of the job |
| model | string |
The base model being fine-tuned |
| fine_tuned_model | null | The name of the resulting fine-tuned model (null while running) |
| training_file | string |
File ID used for training |
| created_at | number |
Unix timestamp of job creation |
| finished_at | null | Unix timestamp of job completion |
| trained_tokens | null | Total billable tokens processed |
| error | null | Error details if the job failed |
| result_files | Array<string> |
Compiled results file IDs |
| hyperparameters | FineTuningJob.Hyperparameters |
Hyperparameters used (for supervised jobs) |
| method | FineTuningJob.Method |
The fine-tuning method used |
Usage Examples
const client = new OpenAI();
// Create a fine-tuning job
const fineTuningJob = await client.fineTuning.jobs.create({
model: 'gpt-4o-mini',
training_file: 'file-abc123',
});
// Retrieve a fine-tuning job
const job = await client.fineTuning.jobs.retrieve('ft-AF1WoRqd3aJAHsqc9NY7iL8F');
// List all fine-tuning jobs with auto-pagination
for await (const fineTuningJob of client.fineTuning.jobs.list()) {
console.log(fineTuningJob.id, fineTuningJob.status);
}
// Cancel a running job
const cancelledJob = await client.fineTuning.jobs.cancel('ft-AF1WoRqd3aJAHsqc9NY7iL8F');
// List events for a job
for await (const event of client.fineTuning.jobs.listEvents('ft-AF1WoRqd3aJAHsqc9NY7iL8F')) {
console.log(event.message);
}
// Pause and resume a job
await client.fineTuning.jobs.pause('ft-AF1WoRqd3aJAHsqc9NY7iL8F');
await client.fineTuning.jobs.resume('ft-AF1WoRqd3aJAHsqc9NY7iL8F');
Key Types
FineTuningJobEvent
interface FineTuningJobEvent {
id: string;
created_at: number;
level: 'info' | 'warn' | 'error';
message: string;
object: 'fine_tuning.job.event';
data?: unknown;
type?: 'message' | 'metrics';
}
FineTuningJobWandbIntegration
interface FineTuningJobWandbIntegration {
project: string;
entity?: string | null;
name?: string | null;
tags?: Array<string>;
}