# Impossible to delete fine-tuned model

**URL:** <https://community.openai.com/t/impossible-to-delete-fine-tuned-model/739772>\
**Category:** API\
**Tags:** fine-tuning-problems\
**Created:** [May 8, 2024, 12:38pm UTC](https://community.openai.com/t/impossible-to-delete-fine-tuned-model/739772 "2024-05-08T12:38:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![agombert](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agombert](https://community.openai.com/u/agombert)\
**Post date:** [May 8, 2024, 12:38pm UTC](https://community.openai.com/t/impossible-to-delete-fine-tuned-model/739772/1 "2024-05-08T12:38:21Z")

</div>

Hello,

I’ve created a project in my account, I’m the account owner. I’ve created an API key related to this account and I’m the only user of it. By default, this API key has all the permissions and as I’m the owner I also have all the permissions.

I’ve trained 3 FT models yesterday and reached my quota. But I can’t delete any of the models.

```python
client.models.delete(my_model_id)

PermissionDeniedError: Error code: 403 - {'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': None, 'code': None}}

```

I don’t understand the problem as I have all permissions set but it looks like there is a problem with the api.delete which may come from the fact that it’s an api from a project created. I tried with the old API but I get a `ModelNotFoundError` and can’t train new one as I’ve reached the quota.

Here is the code I fine tune the model with, maybe it comes from this.

```python
class OpenAIFineTuner:
    """
    Class to fine tune OpenAI models
    """
    def __init__ (self, training_file_path, model_name, suffix):
        self.training_file_path = training_file_path
        self.model_name = model_name
        self.suffix = suffix
        self.file_object = None
        self.fine_tuning_job = None
        self.model_id = None

    def create_openai_file(self):
        self.file_object = client.files.create(
            file=open(self.training_file_path, "rb"),
            purpose="fine-tune",
        )

    def wait_for_file_processing(self, sleep_time=20):
        while self.file_object.status != 'processed':
            time.sleep(sleep_time)
            self.file_object.refresh()
            print("File Status: ", self.file_object.status)

    def create_fine_tuning_job(self):
        self.fine_tuning_job = client.fine_tuning.jobs.create(
        training_file=self.file_object.id,
        model=self.model_name,
        suffix=self.suffix,
    )

    def wait_for_fine_tuning(self, sleep_time=45):
        while self.fine_tuning_job.status != 'succeeded':
            time.sleep(sleep_time)
            self.fine_tuning_job = client.fine_tuning.jobs.retrieve(self.fine_tuning_job.id)
            print("Job Status: ", self.fine_tuning_job.status)

    def retrieve_fine_tuned_model(self):
        self.model_id = client.fine_tuning.jobs.retrieve(self.fine_tuning_job.id).fine_tuned_model
        return self.model_id

    def fine_tune_model(self):
        self.create_openai_file()
        self.wait_for_file_processing()
        self.create_fine_tuning_job()
        self.wait_for_fine_tuning()
        return self.retrieve_fine_tuned_model()

fine_tuner = OpenAIFineTuner(
        training_file_path=join(path_data, f"{n}_industry_stratified.jsonl"),
        model_name="gpt-3.5-turbo",
        suffix=f"{n}_strat_20240507"
    )

```

Any idea ?

Cheers,

Arnault

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [May 8, 2024, 12:58pm UTC](https://community.openai.com/t/impossible-to-delete-fine-tuned-model/739772/2 "2024-05-08T12:58:18Z")

</div>

Yep, it’s an annoyance that’s only been going on for two years.

Delete will disable it - and then you still have a model in the list, but one that doesn’t work.

The limit you hit at 3 is likely active/queued jobs. You’ll just have let some finish. You can check your fine tuning limits in your account to see your particular active limit and to see daily total limit.

---

<div class="post-metadata">

**Author:** ![agombert](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agombert](https://community.openai.com/u/agombert)\
**Post date:** [May 8, 2024, 1:11pm UTC](https://community.openai.com/t/impossible-to-delete-fine-tuned-model/739772/3 "2024-05-08T13:11:08Z")

</div>

The first problem is that you can’t delete the model once it’s fine-tuned (cf the error I’ve put in my earlier post). with a 403 error which does not work but the api key has all permission.

Then when listing the jobs, they all are finished indeed and you can’t remove them.

---

<div class="post-metadata">

**Author:** ![michabbb](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/michabbb/32/222577_2.png) [@michabbb](https://community.openai.com/u/michabbb)\
**Post date:** [October 7, 2024, 11:04am UTC](https://community.openai.com/t/impossible-to-delete-fine-tuned-model/739772/4 "2024-10-07T11:04:13Z")

</div>

Missing scopes: api.delete

same here… is that a bad joke ???
