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!!")

but i was not able to delete the fine tuned model by postman…

always gives me the information, that my api dont have the delete scope, and i just have one apikey and one organization.

Someone can add me in discord for we test together?

You need to send all headers to ensure clarity and success.

Here are the instructions to input and send the headers in Postman using hardcoded credentials:

  1. Open Postman and create a new request (GET, POST, or in this case DELETE).

  2. In the “Headers” tab, add the following headers:

    • Key: Authorization

      • Value: Bearer sk-1234567890abcdef1234
      • (Replace sk-1234567890abcdef1234 with your actual API key associated with the default project, following the format sk- + alphanumeric characters.)
    • Key: OpenAI-Organization

      • Value: org-EXAMPLE12345
      • (This is your OpenAI Organization ID. Replace org-EXAMPLE12345 with the actual organization ID.)
    • Key: OpenAI-Project

      • Value: proj_uJ4s0ttsyd9o0ttsyd9
      • (This is your project ID, replace proj_uJ4s0ttsyd9o0ttsyd9 with the correct matching project ID.)
  3. Send the request by clicking the “Send” button after configuring the rest of your API request, the URL having the model, like https://api.openai.com/v1/models/ft:gpt-4o-mini:acemeco:suffix:abc123

This setup will ensure the correct headers are sent with your API call in Postman. “API”, as in “Application Programming Interface”, should imply some programming or scripting skill, though, even just running someone else’s code.

An even higher level is a user key (previously a standard key) along with just organization being sent, as capabilties can’t be limited.

the fine-tuned model exists in org “Personal” but in a separate project.

i tried this call with my default none-project api key and with a key that has been created inside the project. i only have one org, which is “Personal”.

in both cases I get the same API error ;-(((

so… i don´t really understand what I am doing wrong here…
shall I use a project token or a legacy token ? a token from inside the project or not ?

if I don´t use a project-token, I don´t see the model when doing a “get models” call. if I use a token created in that project, I do see the fine-tuned models - which makes sense. but it would make more sense, if I could delete them with the same token. and btw… all tokens have “All” permissions. there is nothing more than “All” I can choose when creating a token.

so this still is very frustrating ;-((

so, the delete call doesn’t work with:

  • a user legacy token
  • a default project token
  • a token created inside the project where the fine-tuned model got created

I guess no more options are left here ;-((

today i got an update from the support:

Hello Michael,
Thank you for your patience as we look into this issue. We’re currently investigating the inability to delete fine-tuned models created within projects, specifically the missing “api.delete” scope.
Our technical team is actively working on it, and we’ll provide you with further updates as soon as we have more information.
Thank you again for your understanding, and we’re here if you have any other questions in the meantime.,
Best,
Shuarem

this gives me hope that something is actually happening …

this is related to:

2 Likes

glad to hear that openai team are working on it…

Have idea when this will work?

1 Like

some updates about this? from openai?