Count tokens before making API calls. Estimate costs, validate inputs, and optimize your prompts for efficiency.
from mythicdot import MythicDot
client = MythicDot()
# Count tokens for a message
response = client.messages.count_tokens(
model="mythic-4",
messages=[
{
"role": "user",
"content": "What is the meaning of life?"
}
],
system="You are a helpful assistant."
)
print(f"Input tokens: {response.input_tokens}")
# Estimate cost before calling
cost_per_million = 3.00 # Example pricing
estimated_cost = (response.input_tokens / 1_000_000) * cost_per_million
print(f"Estimated input cost: ${estimated_cost:.6f}")
Count tokens to estimate costs and improve efficiency.