Skip to main content
Note:When running survey jobs your prompts and responses are cached automatically and can be retrieved again later at no cost. Learn more about remote inference caching in the remote-caching section of the docs.

Estimating costs

When you create a survey, you can estimate the cost of running it before actually running it. This is done by combining the survey with one or more models to create a Job object. The Job object contains all the information needed to run the survey, including the models and inference services used. There are 2 methods of estimating costs (in USD and credits):
  • Call the estimate_job_cost() method on a Job object (a survey combined with one or more models). This will return the total estimated cost in USD, the estimated input and output tokens, and estimated costs and tokens for each inference service and model used. It will also show the number of credits that will be placed on hold if the survey job is run remotely. Once the job has completed the credits are released and final calculated credits are deducted from your account.
  • Call the remote_inference_cost() method on a Coop client object and pass it the job. This will return the total estimated cost in USD and credits.
Credits are required to run surveys remotely. Learn more about using credits in the Credits </en/latest/credits>_ section of the docs. For example:
This will return:
Using the Coop client object instead:
This will return:

Calculations

The above-mentioned methods use the following calculation for each question in a survey to estimate the total cost of the job:
  1. Estimate the input tokens.
    • Compute the number of characters in the user_prompt and system_prompt, with any Agent and Scenario data 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.)
  2. Estimate the output tokens.
    • Apply a multiplier of 0.75 to the number of input tokens, rounding up to the nearest whole number.
  3. 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
  4. 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.
Then sum the costs for all question prompts to get the total cost of the job. A notebook example is available here.

Tracking costs

After running a survey job, you can track the actual token costs incurred for each question in the raw_model_response columns of the Results that are generated for your survey:
  • raw_model_response.<question_name>_cost: The cost of the result for the relevant question, applying the token quanities & prices.
  • raw_model_response.<question_name>_input_price_per_million_tokenss: The price per million input tokens for the relevant question for the relevant model.
  • raw_model_response.<question_name>_input_tokens: The number of input tokens for the relevant question for the relevant model.
  • raw_model_response.<question_name>_one_usd_buys: The number of identical results for the relevant question that 1USD would cover.
  • raw_model_response.<question_name>_output_price_per_million_tokens: The price per million output tokens for the relevant question for the relevant model.
  • raw_model_response.<question_name>_output_tokens: The number of output tokens for the relevant question for the relevant model.
  • raw_model_response.<question_name>_raw_model_response: The raw model response for the relevant question.
Details can also be viewed at the Jobs and Transactions pages of your Expected Parrot account. For example, here we inspect the costs of running the job from above:
Output: We can see the details at Expected Parrot as well. Your Jobs page will show the actual costs of each survey job. Your Transactions page will show the additional information about credits on hold based on cost estimates together with actual costs of each survey job. For more on credits, please see the Credits section of the docs.