Is the current model pricing available via the API?

Hi,

I found this list for the current prices per token for the various models:

It would be very convenient if those prices were available via the API, too.

For instance, it would be great if the below list would also contain the current prices per token, which, afaik, it doesn’t.

import openai
openai.Model.list()

Does someone know whether it is currently possible to obtain the pricing information programmatically?

Thank you for your help!

2 Likes

It is not available, but you can start filling the data into this template to make a function…

import openai
openai.api_key = key

try:
    models_api = openai.Model.list()
    pass
except Exception as err:
    print(f"Error updating model list: {err}")

model_ids = [model.id for model in models_api["data"]]
model_ids.sort()
models = {model: {'price_in': -1, 'price_out': -1, 'price_train': -1,
                  'endpoint': '?', 'tokenizer': '?', 'retire_date': '?'
                  } for model in model_ids}
print(f"# -- Price template for {len(models)} models from account --")
print ("model_metadata = {")
for model, props in models.items():
    print("" + f"'{model}': {props}," + "")
print ("}")

output:

# – Price template for 61 models from account –
model_metadata = {
‘ada’: {‘price_in’: -1, ‘price_out’: -1, ‘price_train’: -1, ‘endpoint’: ‘?’, ‘tokenizer’: ‘?’, ‘retire_date’: ‘?’},
‘ada-code-search-code’: {‘price_in’: -1, ‘price_out’: -1, ‘price_train’: -1, ‘endpoint’: ‘?’, ‘tokenizer’: ‘?’, ‘retire_date’: ‘?’},
‘ada-code-search-text’: {‘price_in’: -1, ‘price_out’: -1, ‘price_train’: -1, ‘endpoint’: ‘?’, ‘tokenizer’: ‘?’, ‘retire_date’: ‘?’},

(I tried to get GPT-4 to fill this in from three web pages of model and price info, but it failed, producing incomplete sparse output from the provided template each time)

1 Like

Thanks a lot for the above code snippet! In fact, I had the same idea to let it parse the web-site. Good to know to this is not so easy. I will then follow your advice and for now manually maintain a little “pricing database” within the code.

Well, I got inspired and spent about 8 hours going through everything on the OpenAI site and Azure and what was archived, and then probed all the models, and then compared vectors of the models etc to make a quite extensive database. Working on the class methods now so it behaves more import-y and object-y.

def init_model_list():
    self.model_list = {
        'ada':                      {'price_class': 'ada',        'endpoint': 'complete', 'tokenizer': 'r50k_base', 'context': 2049, 'cutoff': '2019-10', 'retire_date': '2024-01-04', 'tune': 'oldtune'},
        'ft:ada':                   {'price_class': 'ft-ada',        'endpoint': 'complete', 'tokenizer': 'r50k_base', 'context': 2049, 'cutoff': '2019-10', 'retire_date': '2024-01-04', 'tune': 'oldtune'},
        'babbage':                  {'price_class': 'babbage',    'endpoint': 'complete', 'tokenizer': 'r50k_base', 'context': 2049, 'cutoff': '2019-10', 'retire_date': '2024-01-04', 'tune': 'oldtune'},
        'ft:babbage':               {'price_class': 'ft-babbage',    'endpoint': 'complete', 'tokenizer': 'r50k_base', 'context': 2049, 'cutoff': '2019-10', 'retire_date': '2024-01-04', 'tune': 'oldtune'},
        'babbage-002':              {'price_class': 'babbage-002', 'endpoint': 'complete', 'tokenizer': 'cl100k_base', 'context': 16385, 'cutoff': '2021-09', 'retire_date': '', 'tune': 'tune'},
        'ft:babbage-002':           {'price_class': 'ft-babbage-002', 'endpoint': 'complete', 'tokenizer': 'cl100k_base', 'context': 16385, 'cutoff': '2021-09', 'retire_date': '', 'tune': 'tune'},
        'babbage-search-query':     {'price_class': 'babbage',    'endpoint': 'embed', 'tokenizer': 'r50k_base', 'context': 2046, 'cutoff': '2019-10', 'retire_date': '2024-01-04'},
        'code-davinci-edit-001':    {'price_class': 'davinci',    'endpoint': 'edit', 'tokenizer': 'p50k_base', 'context': 8001, 'cutoff': '2021-06', 'retire_date': ''},
        # 'code-davinci-002':         {'price_class': 'davinci',    'endpoint': 'complete', 'tokenizer': 'p50k_base', 'context': 8001, 'cutoff': '2021-06', 'retire_date': '2023-03-23'},  # Azure only

And what has not been explained anywhere I can answer - what all those bizarre embedding names are…

def init_model_aliases():
    ''' Match of embedding model alias verified by vector
    response = openai.Embedding.create(input="x", model = model)
    print("{" + f"'{model}': '{response['model']}', 'dim': {(response['data'][0]['embedding'][512])}" + "},")
    '''
    
    self.embed_alias = [
        {'ada-search-document': 'text-search-ada-doc-001', 'reported': 'text-search-ada:001', 'dim': -0.03518218919634819},
        {'curie-search-document': 'text-search-curie-doc-001', 'reported': 'text-search-curie:001', 'dim': -0.02822701632976532},
        {'curie-search-query': 'text-search-curie-query-001', 'reported': 'text-search-curie:001', 'dim': -0.027747787535190582},
        {'ada-similarity': 'text-similarity-ada-001', 'reported': 'text-similarity-ada:001', 'dim': -0.01897580549120903},
        {'curie-similarity': 'text-similarity-curie-001', 'reported': 'text-similarity-curie:001', 'dim': -0.010900501161813736},
        {'davinci-search-document': 'text-search-davinci-doc-001', 'reported': 'text-search-davinci:001', 'dim': -0.00792695488780737},
        {'davinci-similarity': 'text-similarity-davinci-001', 'reported': 'text-similarity-davinci:001', 'dim': -0.0036240890622138977},
        {'ada-code-search-text': 'code-search-ada-text-001', 'reported': 'code-search-ada:001', 'dim': -0.0007537906058132648},
        {'babbage-similarity': 'text-similarity-babbage-001', 'reported': 'text-similarity-babbage:001', 'dim': 0.0017362049547955394},
        {'davinci-search-query': 'text-search-davinci-query-001', 'reported': 'text-search-davinci:001', 'dim': 0.00517953559756279},
        {'babbage-code-search-text': 'code-search-babbage-text-001', 'reported': 'code-search-babbage:001', 'dim': 0.006059383973479271},
        {'babbage-code-search-code': 'code-search-babbage-code-001', 'reported': 'code-search-babbage:001', 'dim': 0.006370352115482092},
        {'babbage-search-document': 'text-search-babbage-doc-001', 'reported': 'text-search-babbage:001', 'dim': 0.01109246164560318},
        {'ada-search-query': 'text-search-ada-query-001', 'reported': 'text-search-ada:001', 'dim': 0.03154809772968292},
        {'ada-code-search-code': 'code-search-ada-code-001', 'reported': 'code-search-ada:001', 'dim': 0.07346884906291962},
    ]

All these names starting with the model alphabet class point to another…

1 Like

Yes, it would be great to have the current pricing available as API endpoint.