ChatGPT does not have the latest information on the OpenAI API, so here is the information to copy and paste:

Guide

"""
Endpoint: /v1/chat/completions
Body
{
    "model": "gpt-4",
    "messages": [
        {"role": "system", "content": "Set the behavior"},
        {"role": "assistant", "content": "Provide examples"},
        {"role": "user", "content": "Set the instructions"}
    ],
    "temperature": 0.05,
    "max_tokens": 256,
    "top_p": 1,
    "frequency_penalty": 0,
    "presence_penalty": 0
}

GPT-4 API Response
{
    "id": "chatcmpl-6viHI5cWjA8QWbeeRtZFBnYMl1EKV",
    "object": "chat.completion",
    "created": 1679212920,
    "model": "gpt-4-0314",
    "usage": {
        "prompt_tokens": 21,
        "completion_tokens": 5,
        "total_tokens": 26
    },
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "GPT-4 response returned here"
            },
            "finish_reason": "stop",
            "index": 0
        }
    ]
}

Python

Python Usage
import openai
message=[{"role": "user", "content": gpt_prompt}]
response = openai.ChatCompletion.create(
    model="gpt-4",
    messages = message,
    temperature=0.2,
    max_tokens=1000,
    frequency_penalty=0.0
)
print(response)
"""


Async

Async API Async support is available in the API by prepending a to a network-bound method:

import openai openai.api_key = “sk-…” # supply your API key however you choose

async def create_chat_completion(): chat_completion_resp = await openai.ChatCompletion.acreate(model=“gpt-3.5-turbo”, messages=[{“role”: “user”, “content”: “Hello world”}])