Issue with Accessing Custom Assistant via OpenAI API using PowerShell

Hello,

I am having trouble accessing my custom assistant via the OpenAI API using PowerShell. I have confirmed that my API key, Assistant ID, and the format of my request are correct. I have also verified that my assistant is properly set up and active.

Here’s the PowerShell command I’m using:

$headers = @{
    "Content-Type" = "application/json"
    "Authorization" = "Bearer {API_KEY}"
}

$body = @{
    "messages" = @(
        @{
            "role" = "user"
            "content" = "This is a test message for the custom assistant"
        }
    )
} | ConvertTo-Json

$response = Invoke-WebRequest `
    -Uri "https://api.openai.com/v1/assistants/{ASSISTANT_ID}/messages" `
    -Method Post `
    -Headers $headers `
    -Body $body `
    -UseBasicParsing

$response.Content

(Note: {API_KEY} and {ASSISTANT_ID} are placeholders for my actual API key and Assistant ID.)

When I run this command, I receive the following error:

Invoke-WebRequest : {
  "error": {
    "message": "Invalid URL (POST /v1/assistants/{ASSISTANT_ID}/messages)",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

I have successfully connected to the general model endpoint using PowerShell, and I can list all the assistants available to me. However, when I try to connect to my custom assistant, I get the “Invalid URL” error.

I have reviewed the configuration of my assistant in the OpenAI dashboard and everything seems to be in order. I’m not sure what else could be causing this issue.

Any help would be greatly appreciated. Thank you!

Welcome @DaveSize

I can see that this code is not suitable for consuming the assistants API.

Assistants function differently from models; models are stateless, while assistants have specific instructions, knowledge, and messages in their threads.

Here is a high-level outline to consume assistants:

  1. Create an assistant.
  2. Create a thread.
  3. Create messages on the thread.
  4. Run the thread on the assistant created in first step.

Here’s the Assistants API reference for more information.

4 Likes

Thank you very much! I’ll look into it.