Can Anypone provide a CURL example of assistant V2?

currently trying to get an assistant’s response to a prompt using CURL, can anyone provide an example on how to do so?

To get a response from an Assistant you first need to create a Thread and attach message to it and RUN the thread using Assistant ID. When you say trying to get response from Assistant, what exactly do you mean. Can you add more details?

Im trying to get a single response to my prompt (without previous context) from the assistant; Im a complete beginner so care making an example using CURL?

Read the docs again, seems like my issue is that I just completely don’t know how to use assistant APIs, mind providing CURL examples of creating a thread, sending a message through the thread and getting the response?

1 Like
  1. Create a Thread:
curl https://api.openai.com/v1/threads \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d ''
  1. Create a Message
curl https://api.openai.com/v1/threads/thread_abc123/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
      "role": "user",
      "content": "How does AI work? Explain it in simple terms."
    }'

Make sure to replace “thread_abc123” with the Thread Id you received in step 1.

  1. Run the Thread:
curl https://api.openai.com/v1/threads/thread_abc123/runs \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
    "assistant_id": "asst_abc123"
  }'

Make sure to replace ThreadID and Assistant Id.

  1. To see the result, retrieve Thread:
curl https://api.openai.com/v1/threads/thread_abc123 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2"
2 Likes

Very helpful explanation. You saved my day! Thanks

1 Like