- Call the
estimate_job_cost()method on theJobobject (a survey combined with one or more models). This will return the total estimated cost in USD, the total estimated input and output tokens, and estimated costs and tokens for each inference service and model used. - Call the
remote_inference_cost()method on aCoopclient object and pass it the job. This will return the estimated cost in credits and USD. (Credits are required to run surveys remotely. Learn more about using credits in the Credits section of the docs.)
Calculations
The above-mentioned methods use the following calculation for each question in a survey to estimate the total cost of the job:- Estimate the input tokens.
- Compute the number of characters in the
user_promptandsystem_prompt, with anyAgentandScenariodata piped in. (Note: Previous answers cannot be piped in because they are not available until the survey is run; they are left as Jinja-bracketed variables in the prompts for purposes of estimating tokens and costs.) - Apply a piping multiplier of 2 to the number of characters in the user prompt if it has an answer piped in from a previous question (i.e., if the question has Jinja braces). Otherwise, apply a multiplier of 1.
- Convert the number of characters into the number of input tokens using a conversion factor of 4 characters per token, rounding down to the nearest whole number. (This approximation was established by OpenAI.)
- Compute the number of characters in the
- Estimate the output tokens.
- Apply a multiplier of 0.75 to the number of input tokens, rounding up to the nearest whole number.
- Apply the token rates for the model and inference service.
- Find the model and inference service for the question in the Pricing page: Total cost = (input tokens input token rate) + (output tokens * output token rate)*
- If the model is not found, a default price for the inference service provider is used. If both the model and the inference service provider are not found, the following fallback token rates are applied (you will also see a warning message that a model price was not found):
- USD 1.00 per 1M input tokens
- USD 1.00 per 1M ouput tokens
- Convert the total cost in USD to credits.
- Total cost in credits = total cost in USD * 100, rounded up to the nearest 1/100th credit.
Example
Here we create an example survey and agent, select a model and combine them to create a job. Then we call the above-mentioned methods for estimating costs and show the underlying calculations. For more details, please see the Credits section of the docs.| user_prompt | system_prompt | interview_index | question_name | scenario_index | agent_index | model | estimated_cost | cache_keys | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | What is the name of your favorite flower? | You are answering questions as if you were a human. Do not break character.Your traits: | 0 | favorite_flower | 0 | 0 | gpt-4o | 0.000438 | [‘2c5868d1cffbd9b0c2c31cfe8f05b75b’] |
| 1 | What color is? | You are answering questions as if you were a human. Do not break character.Your traits: | 0 | flower_color | 0 | 0 | gpt-4o | 0.000440 | [‘25a1f3576a97e3d6aa304d2b152e207a’] |
