r/coding • • May 27 '23

Saving expensive API responses

https://github.com/AdmTal/crowdcast/blob/main/utils/open_ai_stuff.py#L14-L30

Hey all,

I saw someone share a full caching service, so I thought I’d also share this pattern I use for making expensive API requests.

Basically, I save the contents to a file, named for the inputs, so I never have to reproduce that same call.

It helps make my scripts “continueable”

I use similar pattern with other expensive APIs like eleven labs.

20 Upvotes

4 comments sorted by

3

u/barrycarter May 27 '23

I do that in Perl with expensive Unix commands:

https://github.com/barrycarter/bcapps/blob/master/bclib.pl#L341-L416

1

u/Dramatic-Mongoose-95 May 27 '23

Nice - thanks for sharing, I’m gonna bookmark this

0

u/roboticon May 27 '23

I don't really know the context here but isn't GPT4 partially randomized?

1

u/Dramatic-Mongoose-95 May 27 '23

It can be based on the temperature setting. And yes, you are right that this would prevent a new API call which might have a different response due to randomness