Reducing Context Tokens in Assistant Threads

They want you to rat out on where you read that API methods exist…methods that would be far too useful to continue to allow developers access. To an email address they now don’t check.

“missing scope” is an interesting message - you’ve not been granted the permission.


Verify it myself with a script to create a thread and message, then try to delete the message and delete the thread.

Some Python
import os, requests
body = {"role": "user", "content": "Delete me!"}
url = "https://api.openai.com/v1/threads"
asst_header = {"Content-Type": "application/json", 
               "OpenAI-Beta": "assistants=v1",
               "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}"
               }

# create thread
try:
    response = requests.post(url, headers=asst_header, json="")
except Exception as e:
    print(f"Error creating thread: {e}")
    raise
if response.status_code != 200:
    print(f"HTTP error {response.status_code} creating thread: {response.text}")
    raise ValueError("Error creating thread")
else:
    print(response.reason + " " + response.url)
    thread_id = response.json()['id']
    print(thread_id)

# create message
try:
    response = requests.post(url + "/" + thread_id + "/messages",
                             headers=asst_header, json=body)
except Exception as e:
    print(f"Error creating thread: {e}")
    raise
if response.status_code != 200:
    print(f"HTTP error {response.status_code} creating thread: {response.text}")
    raise ValueError("Error creating message")
else:
    print(response.reason + " " + response.url)
    message_id = response.json()['id']
    print(message_id)

# delete message
try:
    delete = requests.delete(url + "/" + thread_id + "/messages/" + message_id,
                           headers=asst_header)
except Exception as e:
    print(f"Error deleting message: {e}")
if delete.status_code != 200:
    print(f"HTTP error {delete.status_code} deleting message: {delete.text}")
else:
    print(delete.json())

# delete thread (cleanup)
try:
    delete = requests.delete(url + "/" + thread_id,
                           headers=asst_header)
except Exception as e:
    print(f"Error deleting thread: {e}")
if delete.status_code != 200:
    print(f"HTTP error {delete.status_code}: {delete.text}")
else:
    print(delete.json())
OK https://api.openai.com/v1/threads
thread_CprqhbJDpBCcwTkOTieiMlcg
OK https://api.openai.com/v1/threads/thread_CprqhbJDpBCcwTkOTieiMlcg/messages
msg_vIcwPQafwJSxqvSNbZ8kSZZh
HTTP error 401 deleting message: {
  "error": {
    "message": "You've made a request to an admin-only URL. If you're an OpenAI employee, please request the necessary permissions. If not, it's our mistake that you're trying to access this URL -- please let us know how you found it at support@openai.com.",
    "type": "invalid_request_error",
    "param": null,
    "code": "missing_scope"
  }
}
{'id': 'thread_CprqhbJDpBCcwTkOTieiMlcg', 'object': 'thread.deleted', 'deleted': True}
1 Like

Why not use the truncation_strategy parameter in run object? i’m assuming this thread is about GPT Assistant API.