View this page on GitHub

OpenAI Chat Completion Request

  client = OpenAI(api_key="<OPENAI_API_TOKEN>")

# Create a request to the Chat Completions endpoint
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "user", "content": "In the context of marketing for a new Italian family-style restaurant, generate a marketing slogan to be used in marketing materials including a website and print."}],
  max_completion_tokens=100
)

print(response.choices[0].message.content)