openai.NotFoundError: Error code 404, python cant find assistant

I have copied my api key from playground and copied my assistants ID from the website so a spelling erorr is out of the question, ive even tried to make a new assitant and it had the same error for me. I use OpenAI version 1.37
The problem is it acts as if the ai dosent exist. and it definiteley does. there is money on the account so it should work.

My code:
from openai import OpenAI

client = OpenAI(api_key=“api key”)
def ask_my_assistant(prompt):
response = client.completions.create(model=“my assistant”, # Replace with your assistant’s ID
return response.choices[0].text.strip()

Example usage

response = ask_my_assistant(“Hello, how can I help you today?”)

I get this error:
openai.NotFoundError: Error code: 404 - {‘error’: {‘message’: ‘The model asst_xxxxxxxxxxxxxxxx does not exist’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: ‘model_not_found’}}


Was this ever resolved? I feel like I have everything nailed down but continued to get error as if the assistant does not exist.


I have the exact same issue: I can create a client. The chat completion API works fine. But when I try to create an assistant, it gives me a “NotFoundError: Error code: 404 - {‘error’: {‘code’: ‘404’, ‘message’: ‘Resource not found’}}”

Any help would be appreciated!

For those running into the same issue: I updated the API version to “2024-02-15-preview”, which solved my issue.

I am currently utilizing Flask with the request module, and all IDs appear to be functioning correctly. However, when attempting to make a request via a client (such as a website) to the OpenAI assistant, it consistently fails:

:2024-03-10 16:00:55,290 - INFO - - - [10/Mar/2024 16:00:55] “OPTIONS /ask HTTP/1.1” 200 -

2024-03-10 16:00:55,794 - INFO - Response from OpenAI API for thread creation: 200 - {‘id’: ‘thread_ViOf8KzAoSLI7CGyjEfmBPOG’, ‘object’: ‘thread’, ‘created_at’: 1710079255, ‘metadata’: {}}

2024-03-10 16:00:56,161 - INFO - Response from OpenAI API for adding message to thread: 404 - {‘error’: {‘type’: ‘invalid_request_error’, ‘code’: ‘unknown_url’, ‘message’: ‘Unknown request URL: POST /v1/2024-02-15-preview/assistants/OPENAI_ASSISTANT_ID/messages. Please check the URL for typos, or see the docs at ht…://’, ‘param’: None}}

2024-03-10 16:00:56,162 - ERROR - Error from OpenAI API: 404 Client Error: Not Found for url: ht…://

2024-03-10 16:00:56,165 - INFO - - - [10/Mar/2024 16:00:56] “[35m[1mPOST /ask HTTP/1.1[0m” 500 -

what an i doing wrong?

I am facing the same issue with a fine-tuning job. Everything works fine and even says it was a success. But when I try to generate response it give the same error. Does anyone know how to solve this? I also tried updating the version but doesn’t work.

The first question is if you are using chat.completions or the assistants API. Then, if you have ensured the API key (typically set as environment variable OPENAI_API_KEY) is one for the training organization.

Then the model name. The ability to use fine-tuning models in assistants has only just been enabled. The only model that they will allow is gpt-3.5-turbo-0125, however.

You can list your fine tune models with this endpoint Python script I wrote up that shows all fine-tunes, and then for you, only those compatible with assistants, using the latest openai Python module. That will show you your true model name with created date if it is ready for use.

from typing import List, Optional
from openai import OpenAI
import datetime
import locale

def filter_models(starts_with: Optional[List[str]] = ["gpt", "ft:gpt"], blacklist: Optional[List[str]] = ["instruct"]) -> List[tuple]:
    Fetches and filters model names and creation dates from the OpenAI API based on specified criteria.
        starts_with (List[str]): A list of prefixes to include models that start with any of them.
        blacklist (List[str]): A list of substrings to exclude models that contain any of them.
        List[tuple]: A list of filtered model tuples (model name, creation date) that meet the criteria.
    client = OpenAI()
        model_obj = client.models.list()  # API call
    except Exception as err:
        raise ValueError(f"Model listing API call failed: {err}") from None
    model_list = sorted([(, model.created) for model in], key=lambda x: x[0])

    def starts_with_any(model_tuple: tuple, starts_with_list: List[str]) -> bool:
        return any(model_tuple[0].startswith(prefix) for prefix in starts_with_list)

    def contains_blacklisted(model_tuple: tuple, blacklist: List[str]) -> bool:
        return any(blacklisted in model_tuple[0] for blacklisted in blacklist)

    filtered_models = [model for model in model_list
                       if starts_with_any(model, starts_with)
                       and not contains_blacklisted(model, blacklist)]

    return filtered_models

locale.setlocale(locale.LC_ALL, '')

default_filtered_models = filter_models(["ft:"])
print("-- All fine-tune models --")
if default_filtered_models:
    print("\n".join(f"{model[0]}, Created: {datetime.datetime.fromtimestamp(model[1]).strftime('%c')}" for model in default_filtered_models))
    print("No models meeting criteria")

default_filtered_models = filter_models(["ft:gpt-3.5-turbo-0125"])
print("-- Fine-tune models compatible with Assistants --")
if default_filtered_models:
    print("\n".join(f"{model[0]}, Created: {datetime.datetime.fromtimestamp(model[1]).strftime('%c')}" for model in default_filtered_models))
    print("No models meeting criteria")

Example output:

-- All fine-tune models --
ft:gpt-3.5-turbo-0613:my_org::83govGjy, Created: 9/28/2023 1:37:58 AM
ft:gpt-3.5-turbo-1106:my_org::8IkEWw8r, Created: 11/8/2023 1:18:36 PM
-- Fine-tune models compatible with Assistants --
No models meeting criteria

The date should be localized for you.

Happy bot chat!

Hi, thank you for your response. I ran the code snippet that you attached and it is showing the fine-tune models that I created. But I still cannot generate response. I am attaching my code below. Can tell me what I am doing wrong?

import pandas as pd
df = pd.read_csv("/content/machine screws.csv") # enter the location of your data path

def convert_to_gpt35_format(dataset):
    fine_tuning_data = []
    for _, row in dataset.iterrows():
            "messages": [
                {"role": "user", "content": row['Input']},
                {"role": "assistant", "content": row['Output']} #json_response}
    return fine_tuning_data

converted_data = convert_to_gpt35_format(df)

from sklearn.model_selection import train_test_split

# Stratified splitting. Assuming 'Top Category' can be used for stratification
train_data, val_data = train_test_split(
    random_state=42  # for reproducibility

import json
def write_to_jsonl(data, file_path):
    with open(file_path, 'w') as file:
        for entry in data:
            json.dump(entry, file)

training_file_name = "train_a.jsonl"
validation_file_name = "val_a.jsonl"

write_to_jsonl(train_data, training_file_name)
write_to_jsonl(val_data, validation_file_name)

from openai import OpenAI
client = OpenAI(api_key="MY_KEY")

# Upload Training and Validation Files
training_file = client.files.create(
    file=open(training_file_name, "rb"), purpose="fine-tune"
validation_file = client.files.create(
    file=open(validation_file_name, "rb"), purpose="fine-tune"

# Create Fine-Tuning Job
response =,,

# Print the result
print("Fine-Tuning Job ID:",
print("Status:", response.status)
print("Created at:", response.created_at)

job_id =

prompt = " 1-8 X 15 FLAT SLTD MACH SCREW 3 THRD HDG "

response =
        model=job_id, messages=prompt, temperature=0, max_tokens=50

# Access the generated text from the response
prediction_text = response.choices[0].text.strip()
print(f"Predicted code: {prediction_text}")

The next thing to investigate is the new “projects” system for managing API keys.

Since it allows model-level granularity in assigning rights, the new model may not have been populated into an existing API key automatically. OpenAI dumped this system on us without much documentation.

A project has a list of models under settings->“limits”, where you can either allow or block models that are checked. This should have your new fine-tune model.

Generate a new key within a project that is unrestricted, and then employ that new API key, and see if that solves all your problems.

Also, you provided code that both does fine tune operations and also does a completions inference.

These should be quite separate. A fine-tuning job can take hours of queue to complete, and then you should validate it independently.

1 Like

Thank you so much, I’ll follow your advice!