代码
LiteLLM
用 openai/ 前缀和 api_base 把 LiteLLM 指向 nokeep。它在代理和 Python SDK 中都能用。
核对于 2026年10月29日
代理
model_list:
- model_name: deepseek-v4.1-flash-uncensored
litellm_params:
model: openai/deepseek-v4.1-flash-uncensored
api_base: https://nokeep.ai/v1
api_key: os.environ/NOKEEP_API_KEY
model_info:
input_cost_per_token: 0.00000045
cache_read_input_token_cost: 0.000000011
output_cost_per_token: 0.00000175
- model_name: glm-5.3-flash-uncensored
litellm_params:
model: openai/glm-5.3-flash-uncensored
api_base: https://nokeep.ai/v1
api_key: os.environ/NOKEEP_API_KEY
model_info:
input_cost_per_token: 0.0000002
cache_read_input_token_cost: 0.00000004
output_cost_per_token: 0.00000065pip install 'litellm[proxy]'
export NOKEEP_API_KEY="sk-nokeep-test" # your own key once it connects
litellm --config config.yaml你的应用随后用 model_name 调用代理(默认为 http://0.0.0.0:4000),再由代理调用 nokeep。model_info 为 LiteLLM 提供 nokeep 按每个 token 计算的价格,使其用量统计与你的账单一致。没有它,LiteLLM 就不知道 nokeep 模型的价格,也无法统计调用费用。
Python SDK
pip install litellm
export NOKEEP_API_KEY="sk-nokeep-test" # your own key once it connectsimport os
import litellm
reply = litellm.completion(
model="openai/deepseek-v4.1-flash-uncensored",
api_base="https://nokeep.ai/v1",
api_key=os.environ["NOKEEP_API_KEY"],
messages=[{"role": "user", "content": "Name three good names for a tavern."}],
)
print(reply.choices[0].message.content)
print(reply.usage)LiteLLM 已有一项添加原生 nokeep 提供方的提议。在它发布之前,接入方式是 openai/ 前缀加 api_base;请求会原样发送。
流式输出
import os
import litellm
stream = litellm.completion(
model="openai/deepseek-v4.1-flash-uncensored",
api_base="https://nokeep.ai/v1",
api_key=os.environ["NOKEEP_API_KEY"],
messages=[{"role": "user", "content": "Tell me a story in three lines."}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="", flush=True)
if getattr(chunk, "usage", None):
print("\n", chunk.usage)工具、思考与采样参数
import os
import litellm
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather in a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
reply = litellm.completion(
model="openai/deepseek-v4.1-flash-uncensored",
api_base="https://nokeep.ai/v1",
api_key=os.environ["NOKEEP_API_KEY"],
messages=[{"role": "user", "content": "What's the weather in Lisbon?"}],
tools=tools,
reasoning_effort="high",
max_tokens=4000,
extra_body={"min_p": 0.05}, # fields LiteLLM has no argument for
)
print(reply.choices[0].message.tool_calls)使用 openai/ 前缀时,reasoning_effort 和 tools 会原样传递。在代理中,可以在 litellm_params 下为每个模型设置固定字段(例如 reasoning_effort: high),也可以让每个调用方各自发送。参见工具调用和思考。
注意事项
- `reasoning_effort` 只接受模型自身的取值。
deepseek-v4.1-flash-uncensored接受none、low、high、max;glm-5.3-flash-uncensored接受low、high。其他应用传入的minimal、medium和xhigh会按模型最接近的档位运行(medium按high,模型支持时xhigh按max);任何其他值都会返回400 invalid_reasoning_effort。参见思考。 - GLM 自己选择工具。
glm-5.3-flash-uncensored只接受tool_choice为auto或none。强制调用工具(required,或指定某个函数名)会返回400 unsupported_tool_choice。需要强制调用时请用 DeepSeek。 - 模型不支持的字段会被丢弃,而不是拒绝。 调用仍会返回结果,响应头
x-nokeep-ignored会列出被丢弃的内容。GLM 只保留tools、tool_choice和reasoning_effort,因此它的temperature和response_format会被丢弃。参见各模型支持的字段。 - 内容部件仅限文本和图片。
image_url部件可用于deepseek-v4.1-flash-uncensored;GLM 只读文本。音频和文件部件(如 PDF)会返回400 unsupported_input。 - `n` 必须为 1。 需要多个回复时,请发起多次调用。
drop_params: true 会让 LiteLLM 在调用前丢弃它认为提供方无法接受的字段。nokeep 本身已经会丢弃模型不支持的字段,并在 x-nokeep-ignored 中注明,所以你不需要它。
常见问题
我要把 nokeep 密钥写进 config.yaml 吗?
不用。写上 api_key: os.environ/NOKEEP_API_KEY,LiteLLM 启动时会从环境变量中读取密钥。
为什么 LiteLLM 显示 nokeep 调用没有费用?
它不知道 nokeep 的价格。添加上面配置中的 model_info 块即可;其中的价格与你的账单来自同一张价格表。账单本身会把每次调用向上取整到整数积分。