ChatGPTs Python API Overview

What can it do ?

Keno Leon
9 min readApr 7, 2023

--

Hopefully by now ChatGPT needs no introduction, but what if you need to access it through the Python API, and perhaps you are also thinking what can you do via the API that you can’t do through the site ? And this is what we will be talking about today.

— — — — — — — — — ⭐️ BE COOL, SUBSCRIBE TO MEDIUM ! ⭐️ — — — — — — — —

SETUP NOTES:

💰 IT COSTS MONEY TO TRY ! (
But not much) There might or might not be a
free trial when you read this, they cut my free trial/grant while
I was writing this, pricing is somehow affordable (See the
pricing page for up to date prices) but it will depend on your project.

DOCS can be found here: https://platform.openai.com/docs/api-reference/

I am using the Official Python Library which is just a pip install away:

pip install openai

And the repo as it is in active development:

https://github.com/openai/openai-python

⚠️ You also need an API KEY you can get with your OpenAI Account.

The first thing you might want to do is list all the models as you’ll need to choose one in further steps:

import openai
openai.api_key = "YOUR API KEY"

models = openai.Model.list()
for model in models['data']:
print(model['id'])


# >>>
# babbage
# davinci
# text-davinci-edit-001
# babbage-code-search-code
# text-similarity-babbage-001
#…

--

--

Keno Leon
Keno Leon

No responses yet