LiteLLM
Gọi mô hình của cheapaimodel từ LiteLLM Python SDK, hoặc phục vụ các mô hình này qua LiteLLM Proxy.
LiteLLM kết nối với các dịch vụ tương thích OpenAI qua tiền tố mô hình openai/. Bạn có thể dùng trực tiếp từ Python, hoặc khai báo các mô hình của cheapaimodel trong cấu hình LiteLLM Proxy.
| Thiết lập LiteLLM | Giá trị | |
|---|---|---|
| Base URL | api_base | https://api.cheapaimodel.ai/v1 |
| API key | api_key | Key của bạn từ trang API key trong bảng điều khiển |
| ID mô hình | model | openai/deepseek-v4-1-flash: openai/ cộng với bất kỳ ID nào trong danh mục |
Thiết lập
pip install litellmimport os
import litellm
response = litellm.completion(
model="openai/deepseek-v4-1-flash",
api_base="https://api.cheapaimodel.ai/v1",
api_key=os.environ["CHEAPAIMODEL_API_KEY"],
messages=[{"role": "user", "content": "Explain recursion in one sentence."}],
)
print(response.choices[0].message.content)
# Streaming
stream = litellm.completion(
model="openai/deepseek-v4-1-flash",
api_base="https://api.cheapaimodel.ai/v1",
api_key=os.environ["CHEAPAIMODEL_API_KEY"],
messages=[{"role": "user", "content": "Write a haiku about rivers."}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)LiteLLM bỏ tiền tố openai/ trước khi gửi, nên yêu cầu gửi tới /v1/chat/completions sẽ mang "model": "deepseek-v4-1-flash".
Lỗi thường gặp
LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=deepseek-v4-1-flash. Thiếu tiền tốopenai/. LiteLLM dựa vào tiền tố để chọn nhà cung cấp và báo lỗi trước khi gửi bất cứ thứ gì. Viếtopenai/deepseek-v4-1-flash.litellm.NotFoundErrorhoặcInvalid URL (POST /v1/chat/completions/chat/completions).api_basethiếu/v1, hoặc có kèm đường dẫn endpoint. Đặt đúnghttps://api.cheapaimodel.ai/v1.- Embeddings bị trỏ tới cheapaimodel. cheapaimodel chưa có mô hình embedding, nên
litellm.embedding()hoặc một mục embedding trongmodel_listkhông có gì để gọi ở đây. Dùng nhà cung cấp khác cho embeddings. - LiteLLM không hiển thị chi phí cho các lượt gọi này. Bảng giá có sẵn của LiteLLM không gồm các mô hình của cheapaimodel: proxy ghi chi phí là 0, còn
litellm.completion_cost()báo lỗiThis model isn't mapped yet. Chi tiêu thực tế của bạn nằm ở trang Nhật ký trong bảng điều khiển. Để theo dõi trong proxy, đặtinput_cost_per_tokenvàoutput_cost_per_tokenbên dướimodel_infocủa mục đó: lấy giá trên mỗi triệu token ở trang mô hình chia cho 1,000,000.