C# Assistance with OpenAI Assistant API - Invalid URL for /assistants/{id}/completions

Hello everyone,

I’m trying to interact with an assistant I created via OpenAI’s API, but I’m encountering an error regarding an invalid URL when calling the /assistants/{id}/completions endpoint. Here’s the error message:

{
  "error": {
    "message": "Invalid URL (POST /v1/assistants/{id}/completions)",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

It seems that the endpoint is not recognized, but I can’t figure out why. I’m using the OpenAI-Beta header for assistants, as the docs suggest the /assistants endpoint is in beta. Below is my C# code:

public async Task<OperationResult<ChatGptApiResponse>> Assistant(string message, IEnumerable list)
{
    var apiEndpoint = "/assistants/ID/completions";  // Replaced "ID" with my assistant ID

    var requestBody = new
    {
        messages = new[]
        {
            new { role = "user", content = message }
        },
        max_tokens = 150,
        temperature = 0.7
    };

    var headers = new List<KeyValuePair<string, string>>
    {
        new ("OpenAI-Beta", "assistants=v2"),
    };

    var response = await ChatGptClient.PostAsync<ChatGptApiResponse>(apiEndpoint, requestBody, headers);

    if (response is { Status: true, Data: not null })
    {
        return new OperationResult<ChatGptApiResponse> { Data = response.Data, Status = true };
    }

    Console.WriteLine($"Error: {response.Message}");

    return new OperationResult<ChatGptApiResponse> { Message = "Not implemented", Status = false };
}

Things I’ve Tried:

  • Verified the assistant ID is correct.
  • Added the OpenAI-Beta: assistants=v2 header as the docs suggest.
  • Looked for alternative endpoints, but I haven’t found a clear answer.

Question:

Has anyone successfully interacted with an assistant created via OpenAI’s API? Am I missing something in the URL or request structure? Is this endpoint /v1/assistants/{id}/completions supported, or should I use a different approach to call the assistant?

Thank you!

I’m not sure what documentation you are looking at but these are completely fabricated. They are also completely mixing two different concepts together.

I have a suspicion that you are relying on AI to generate your code and ALSO read the documentation for you. Which, isn’t too far off the new-age of programming, but for whatever reason your model is hallucinating.

You need to look at this page:
https://platform.openai.com/docs/assistants/quickstart

It’s very nice to have a model do all the work for you, but I really recommend understanding the process.

2 Likes

Agreed, you beat me to it, I was just reading that documentation, I already have an assistant created to read data of files, I am trying to implemented on our application to assist customer service team to handle better the responses to our customers.

Thanks

No problem.

Out of curiosity, where did you get that endpoint from?

1 Like

You wanna bet? :rofl:

All I see is people wasting each others time posting rubbish generated by AI and wondering why it doesn’t work whilst at the same time polluting the forum with broken code (which will feed back into the monster!)

Read the docs people!! :sweat_smile:

1 Like