Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Openai Openai python Fine Tuned Model Inference

From Leeroopedia
Knowledge Sources
Domains Fine_Tuning, Model_Deployment
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for using fine-tuned models in API calls and managing model lifecycle provided by the OpenAI Python SDK.

Description

Fine-tuned models are used via standard API calls (chat.completions.create) by passing the fine-tuned model ID as the model parameter. The Models resource provides delete() for removing models that are no longer needed.

Usage

Pass job.fine_tuned_model as the model parameter to any chat completions call. Use client.models.delete() to remove unused models.

Code Reference

Source Location

  • Repository: openai-python
  • File: src/openai/resources/models.py
  • Lines: L89-138 (Models.delete sync)
  • File: src/openai/resources/chat/completions/completions.py (create)

Signature

class Models(SyncAPIResource):
    def delete(
        self,
        model: str,
    ) -> ModelDeleted:
        """
        Deletes a fine-tuned model.

        Args:
            model: Model ID to delete (e.g., "ft:gpt-4o-mini:org:suffix:id").
        Returns:
            ModelDeleted with .id and .deleted confirmation.
        """

Import

from openai import OpenAI
# client.chat.completions.create(model=ft_model_id)
# client.models.delete(model=ft_model_id)

I/O Contract

Inputs

Name Type Required Description
model str Yes Fine-tuned model ID from job.fine_tuned_model
messages Iterable[ChatCompletionMessageParam] Yes (inference) Conversation messages

Outputs

Name Type Description
response ChatCompletion Standard chat completion from fine-tuned model
deleted ModelDeleted Confirmation with .id and .deleted=True

Usage Examples

Use Fine-Tuned Model

from openai import OpenAI

client = OpenAI()

# Use the fine-tuned model (same API as standard models)
response = client.chat.completions.create(
    model="ft:gpt-4o-mini-2024-07-18:my-org:my-classifier:abc123",
    messages=[
        {"role": "system", "content": "Classify the following text."},
        {"role": "user", "content": "I love this product!"},
    ],
)
print(response.choices[0].message.content)

Delete Fine-Tuned Model

result = client.models.delete(
    "ft:gpt-4o-mini-2024-07-18:my-org:my-classifier:abc123"
)
print(f"Deleted: {result.deleted}")  # True

Related Pages

Implements Principle

Requires Environment

Page Connections

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