cheapaimodel

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.

Sao chép

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 LiteLLMGiá trị
Base URLapi_basehttps://api.cheapaimodel.ai/v1
API keyapi_keyKey của bạn từ trang API key trong bảng điều khiển
ID mô hìnhmodelopenai/deepseek-v4-1-flash: openai/ cộng với bất kỳ ID nào trong danh mục

Thiết lập

Terminal
pip install litellm
app.py
import 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ết openai/deepseek-v4-1-flash.
  • litellm.NotFoundError hoặc Invalid URL (POST /v1/chat/completions/chat/completions). api_base thiếu /v1, hoặc có kèm đường dẫn endpoint. Đặt đúng https://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 trong model_list khô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ỗi This 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, đặt input_cost_per_token và output_cost_per_token bên dưới model_info của mục đó: lấy giá trên mỗi triệu token ở trang mô hình chia cho 1,000,000.
Sao chép
Mở trong

Trên trang này