Skip to main content

openai_request

Function openai_request 

Source
pub fn openai_request(model: &str, usage: &Value) -> EconomicsRequest
Expand description

Read an OpenAI usage object into the same shape. OpenAI’s input_tokens includes the cached part (input_tokens_details.cached_tokens), where Anthropic’s excludes it; the cached part is moved out so that the three input fields are disjoint for both. OpenAI bills no cache writes, so that field is zero, which is what it is.

use majordomus_cli::economics::usage::openai_request;
let r = openai_request("gpt-5", &serde_json::json!({
    "input_tokens": 1000, "input_tokens_details": {"cached_tokens": 800},
    "output_tokens": 50, "output_tokens_details": {"reasoning_tokens": 30}
}));
assert_eq!((r.input_tokens, r.cache_read_input_tokens, r.cache_creation_input_tokens), (200, 800, 0));
assert_eq!(r.thinking_tokens, Some(30));