Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature suggestion]: Exposing model costs for usage with Custom Providers #940

Open
Codeshark-NET opened this issue Jun 16, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Codeshark-NET
Copy link

Currently I have code like this, hardcoding the model cost into my custom provider, and returning the total cost that way.

// ...

const inputCost = 0.00025 / 1000; //@TODO: Get from provider instead?
const outputCost = 0.00125 / 1000; //@TODO: Get from provider instead?
const totalCost = inputCost * usage.promptTokens + outputCost * usage.completionTokens || undefined;

return {
  // Required
  output: object,

  // Optional
  tokenUsage: {
    total: usage.totalTokens,
    prompt: usage.promptTokens,
    completion: usage.completionTokens
  },

  cost: totalCost
};

From what I can see, it's not exposed currently, but it'd be super cool if I would be able to look up the model name via the provider, "claude-3-haiku-20240307", and get the cost model back to be used in the custom provider like this. 🙌

@SysOverdrive
Copy link

Hey Codeshark,

Cool feature request !

I was also wondering how you accomodated the custom provider did you use the python guide or the Custom Scripts

@Codeshark-NET
Copy link
Author

Hey Codeshark,

Cool feature request !

I was also wondering how you accomodated the custom provider did you use the python guide or the Custom Scripts

Heya @SysOverdrive 🙏 you can check out the full code I'm using here: https://github.com/promptfoo/promptfoo/blob/main/examples/custom-provider/vercelAiSdkExample.js (it should be .mjs)

@dynamicwebpaige
Copy link

@Codeshark-NET Love this feature request!

Would recommend attempting to extract $/tokens this from the API providers, as opposed to adding manually - the cost for input and output tokens seems to be changing fairly rapidly.

@typpo typpo added the enhancement New feature or request label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants