From 712e6038aefc4669d2a06f311c2c4cc9f2b50279 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 23 Sep 2023 12:30:39 -0700 Subject: [PATCH] index.md updates --- docs/my-website/docs/index.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/my-website/docs/index.md b/docs/my-website/docs/index.md index 41545ba525e..e74bae06732 100644 --- a/docs/my-website/docs/index.md +++ b/docs/my-website/docs/index.md @@ -120,8 +120,6 @@ response = completion( -### [Supported Providers 100+ LLMs](./providers) - ## Streaming Set `stream=True` in the `completion` args. @@ -254,7 +252,29 @@ except OpenAIError as e: print(e) ``` -## Calculate Costs & Usage +## Calculate Costs, Usage, Latency + +Pass the completion response to `litellm.completion_cost(completion_response=response)` and get the cost + +```python +from litellm import completion, completion_cost +import os +os.environ["OPENAI_API_KEY"] = "sk-litellm-7_NPZhMGxY2GoHC59LgbDw" + +response = completion( + model="gpt-3.5-turbo", + messages=[{ "content": "Hello, how are you?","role": "user"}] +) + +cost = completion_cost(completion_response=response) +print("Cost for completion call with gpt-3.5-turbo: ", f"${float(cost):.10f}") +``` + +**Output** +```shell +Cost for completion call with gpt-3.5-turbo: $0.0000775000 +``` + ## Caching with LiteLLM