OpenMeter - 按用量计费
OpenMeter 是一个面向 AI/云应用的开源按用量计费解决方案。它集成了 Stripe,便于计费。
快速入门
只需 2 行代码,即可使用 OpenMeter 立即记录您在所有提供商处的响应
从 https://openmeter.cloud/meters 获取您的 OpenMeter API 密钥
litellm.callbacks = ["openmeter"] # logs cost + usage of successful calls to openmeter
- SDK
- PROXY
# pip install openmeter
import litellm
import os
# from https://openmeter.cloud
os.environ["OPENMETER_API_ENDPOINT"] = ""
os.environ["OPENMETER_API_KEY"] = ""
# LLM API Keys
os.environ['OPENAI_API_KEY']=""
# set openmeter as a callback, litellm will send the data to openmeter
litellm.callbacks = ["openmeter"]
# openai call
response = litellm.completion(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Hi 👋 - i'm openai"}
]
)
- 添加到 Config.yaml
model_list:
- litellm_params:
api_base: https://openai-function-calling-workers.tasslexyz.workers.dev/
api_key: my-fake-key
model: openai/my-fake-model
model_name: fake-openai-endpoint
litellm_settings:
callbacks: ["openmeter"] # 👈 KEY CHANGE
- 启动代理
litellm --config /path/to/config.yaml
- 测试一下!
curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--data ' {
"model": "fake-openai-endpoint",
"messages": [
{
"role": "user",
"content": "what llm are you"
}
],
}
'