Unable to delete my fine-tuned model

hello.

I think this is my first post here, and I’m asking for help because I can’t seem to delete a fine-tuned model no matter what I do.

First of all, to make my situation more specific, I’m using a personal account. I’ve been issued a project API key and have been using it to fine-tune my models.

As you may know, after several rounds of fine-tuning, you end up with multiple models, so I wanted to delete the remaining models in favor of the final one. I followed OpenAI’s fine-tuning guide and used the client.model.delete method.

But here’s where I ran into a problem. The model is not deleted with the message shown below.
Below is the error message.

{
  “error”: {
    “message”: “You have insufficient permissions for this operation. Missing scopes: api.delete. Check that you have the correct role in your organization (Owner), and if you're using a restricted API key, that it has the necessary scopes.”,
    “type”: “server_error”,
    “param”: null,
    “code”: null
  }
}

Clearly, it’s my account and the members section shows that I have the owner role. Meanwhile, I tried creating a new project API key and got the same result.

If any of you have encountered a similar situation to mine, I would appreciate your help.

Being an “owner” in this case means using an API key that is not a project key, but what is now called a “user” key for default organization.

Delete has never worked as expected, and is not in the API reference. It can make a fine-tuning non-functional, but it still remains in the models endpoint listing.

Hello.

It’s this reference section, right?
https://platform.openai.com/docs/api-reference/models/delete

I am also suffering from the same phenomenon.
I pray that this problem will be resolved.

i am in the same situation … i have organization but receive:

{
“error”: {
“message”: “You have insufficient permissions for this operation. Missing scopes: api.delete. Check that you have the correct role in your organization (Owner), and if you’re using a restricted API key, that it has the necessary scopes.”,
“type”: “server_error”,
“param”: null,
“code”: null
}
}

i create user, change api key… and nothing… i can’t delete.

I was able to remove the fine-tuning models with the following code in Python:

import requests

def delete_model(model_id, api_key):
    """
    Elimina un modelo entrenado en la API de OpenAI.

    Args:
        model_id (str): ID del modelo a eliminar.
        api_key (str): Clave de API de OpenAI.

    Returns:
        dict: Estado de la eliminación del modelo.
    """
    # Construye la URL del endpoint
    url = f'https://api.openai.com/v1/models/{model_id}'
    
    # Configura los encabezados
    headers = {
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    }
    
    # Realiza la solicitud DELETE
    response = requests.delete(url, headers=headers)
    
    # Verifica el estado de la respuesta
    if response.status_code == 200:
        return response.json()
    else:
        raise Exception(f"Error al eliminar el modelo: {response.status_code}, {response.text}")

# Ejemplo de uso
api_key = 'xxxx'  # Reemplaza con tu clave de API real
model_id = 'ft:gpt-3.5-turbo-0125:personal::9pnAv9Ua45'  # Reemplaza con el ID real del modelo

try:
    result = delete_model(model_id, api_key)
    print('El modelo ha sido eliminado exitosamente.')
    print(result)
except Exception as e:
    print(str(e))

1 Like

I figured out why some configurations could delete and others couldn’t in a brainwave that was “duh, obvious given the error message”:

Send the API key, along with matching project AND organization, in the delete call.

This Python SDK script will

  • use the model name you hard-code
  • dump out your environment variables set in the openai client.
  • Then uses the model endpoint to make sure the model exists, with info.
  • Then deletes only if you type 999
  • Then checks the model endpoint again.

The environment variable values to set are self-documenting:

import openai
client = openai.OpenAI()                 # Set environment variables first
print(f" org:  {client.organization}\n",  # OPENAI_ORG_ID
      f"proj: {client.project}\n",       # OPENAI_PROJECT_ID
      f"key:  {client.api_key}\n")       # OPENAI_API_KEY
model_to_delete = "gpt-3.5-turbo-0125"        # YOUR ft: MODEL ID (to lazy for UI)
try:
    status1 = client.models.retrieve(model_to_delete)
    print("retrieved model info from API")
    for key, val in status1:
        print(f"{key}: {val}")
except Exception as e:
    raise ValueError(e)
choice = input("*"*40+"\nif all info looks correct, "
               "enter '999' to irreversibly delete the model: ")
if choice == "999":
    try:
        status2 = client.models.delete(model_to_delete)
    except Exception as e:
        print('-- delete operation failed!!')
        print(e)
try:
    status3 = print(client.models.retrieve(model_to_delete))
    print("Model is still there!!")
except Exception as e:
    print("Model is gone, call returned error!!")