# Assistants API URL Error - Invalid URL

**URL:** <https://community.openai.com/t/assistants-api-url-error-invalid-url/596290>\
**Category:** API\
**Tags:** api\
**Created:** [January 22, 2024, 1:52am UTC](https://community.openai.com/t/assistants-api-url-error-invalid-url/596290 "2024-01-22T01:52:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![profitprofession](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/profitprofession/32/180262_2.png) [@profitprofession](https://community.openai.com/u/profitprofession)\
**Post date:** [January 22, 2024, 1:52am UTC](https://community.openai.com/t/assistants-api-url-error-invalid-url/596290/1 "2024-01-22T01:52:42Z")

</div>

_Im getting an invalid url error when trying to run an assistant and calling the API, here’s my code:_

from flask import Flask, request, jsonify, send\_from\_directory  
from flask\_cors import CORS  
import requests

# Initialize the Flask application

app = Flask( **name** )  
CORS(app, resources={r"/api/_": {“origins”: "_"}}) # Enable CORS for /api/ routes

# Replace with your actual OpenAI API key

OPENAI\_API\_KEY = ‘your-openai-api-key’

@app.route(‘/’)  
def index():  
# Serve the index.html file  
return send\_from\_directory(app.root\_path, ‘index.html’)

@app.route(‘/api/message’, methods=[‘POST’])  
def send\_message\_to\_assistant():  
# Get user input from the request  
user\_input = request.json.get(‘input’)

```
try:
    # Send the input to the OpenAI assistant
    response = requests.post(
        'https://api.openai.com/v1/assistants/asst_Q ************************** o/messages',
        headers={
            'Authorization': f'Bearer sk-s ******************************************* 6',
            'Content-Type': 'application/json',
            'OpenAI-Beta': 'assistants=v1'
        },
        json={'input': user_input}
    )
    response.raise_for_status() # Raises an HTTPError for bad responses
    return jsonify(response.json())
except requests.exceptions.RequestException as e:
    # Log any errors that occur during the API request
    return jsonify({'error': str(e)}), 500

```

if **name** == ‘ **main** ’:  
# Run the Flask app  
app.run(port=8000)

**Ive been racking my brain for hours…**  
**Checked in Postman also, same error:**

{  
“error”: {  
“message”: “Invalid URL (POST /v1/assistants/asst\_\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/messages)”,  
“type”: “invalid\_request\_error”,  
“param”: null,  
“code”: null  
}  
}

Any help would be appreciated! Thanks in advance!

---

<div class="post-metadata">

**Author:** ![nick.mckenna](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/nick.mckenna/32/289000_2.png) [@nick.mckenna](https://community.openai.com/u/nick.mckenna)\
**Post date:** [January 22, 2024, 11:10am UTC](https://community.openai.com/t/assistants-api-url-error-invalid-url/596290/2 "2024-01-22T11:10:17Z")

</div>

I think that you need to create the Message against a Thread rather than an Assistant:

POST [https://api.openai.com/v1/threads/{thread\_id}/messages](https://api.openai.com/v1/threads/%7Bthread_id%7D/messages)

[https://platform.openai.com/docs/api-reference/messages/createMessage](https://platform.openai.com/docs/api-reference/messages/createMessage)

---

<div class="post-metadata">

**Author:** ![profitprofession](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/profitprofession/32/180262_2.png) [@profitprofession](https://community.openai.com/u/profitprofession)\
**Post date:** [January 22, 2024, 3:00pm UTC](https://community.openai.com/t/assistants-api-url-error-invalid-url/596290/3 "2024-01-22T15:00:51Z")

</div>

Thank you, so we cannot call the assistant with the settings it already has?

Mike

---

<div class="post-metadata">

**Author:** ![nick.mckenna](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/nick.mckenna/32/289000_2.png) [@nick.mckenna](https://community.openai.com/u/nick.mckenna)\
**Post date:** [January 22, 2024, 3:24pm UTC](https://community.openai.com/t/assistants-api-url-error-invalid-url/596290/4 "2024-01-22T15:24:13Z")

</div>

I can’t see anything in the API docs that lets you create a message outside the context of a Thread!

What are you trying to achieve?
