Using the ChatGPT API
2023-03-11 05:47 (3 years ago)
Creating an OpenAI Account
https://platform.openai.com/account/
Registering a Credit Card
https://platform.openai.com/account/billing/overview

Set up paid account → I'm an individual
Setting a Payment Limit Just in Case
https://platform.openai.com/account/billing/limits

Creating an API Key
https://platform.openai.com/account/api-keys

Making a Request with Rest Client
POST https://api.openai.com/v1/chat/completions
Content-Type: application/json
Authorization: Bearer sk-....
{
"model": "gpt-3.5-turbo",
"messages": [{
"role": "user",
"content": "Please tell me 10 delicious dishes that have been trending in the past year."
}]
}
Response
{
"id": "chatcmpl-6....m",
"object": "chat.completion",
"created": 1678513287,
"model": "gpt-3.5-turbo-0301",
"usage": {
"prompt_tokens": 32,
"completion_tokens": 483,
"total_tokens": 515
},
"choices": [
{
"message": {
"role": "assistant",
"content": "\n\n1. Dalgona Coffee - A latte-style drink made by pouring a frothy mixture of coffee, sugar, and water over milk.\n2. Sweet Potato Toast - A sweet dish featuring sweet potato paste, marshmallows, and caramel sauce on toast.\n3. Homemade Yakiniku - A popular dish for home parties and family gatherings, where you can easily make yakiniku at home.\n4. Overnight Oats - A breakfast drink made by mixing oats and almond milk and letting it sit overnight.\n5. Quinoa Balls - A snack made by mixing quinoa and nuts with dates and shaping them into balls.\n6. Tarte aux Fraises - A French tart topped with fruit.\n7. Vegan Seafood - Vegan food designed to mimic seafood.\n8. Marshmallow Brown - A s'mores-style dessert made with chocolate, marshmallows, and graham crackers.\n9. Superfood Smoothie - A smoothie mixed with healthy superfoods.\n10. Hot Pot - A traditional Asian dish where raw meat and vegetables are cooked in hot soup."
},
"finish_reason": "stop",
"index": 0
}
]
}
Pricing
$0.002 (approximately 0.3 yen) / 1K tokens So, for this one request, it costs about 0.15 yen.
Impressions
I think it depends on the model, but it is significantly slower than using it on the web.
API Documentation
Please rate this article
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.