Skip to content
The Chat Archive
gpt-4o-2024-05-13· OpenAI WildChat-4.8M (AI2)

curl https://chatgpt-api.shn.hk/v1/ \ -H 'Content-Type: application/json' \ -d '{…

  1. User

    curl https://chatgpt-api.shn.hk/v1/
    -H 'Content-Type: application/json'
    -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello, how are you?"}] }'

    python requests code

  2. Assistant

    Certainly! Here’s how you can make the same request using the Python requests library:

    import requests
    import json
    
    url = "https://chatgpt-api.shn.hk/v1/"
    headers = {
        "Content-Type": "application/json"
    }
    data = {
        "model": "gpt-3.5-turbo",
        "messages": [{"role": "user", "content": "Hello, how are you?"}]
    }
    
    response = requests.post(url, headers=headers, data=json.dumps(data))
    
    # Print the response from the API
    print(response.json())
    

    In this code:

    • requests.post is used to make a POST request to the provided URL.
    • headers specify the 'Content-Type' as 'application/json'.
    • data contains the payload we want to send, which is a dictionary.
    • json.dumps(data) converts the dictionary data into a JSON formatted string.
    • The response from the API is then printed in JSON format by using response.json().

    Make sure you have the requests library installed. You can install it using pip if you haven’t already:

    pip install requests