跳至主要內容

Nebius AI Studio

https://docs.nebius.com/studio/inference/quickstart

提示

**Litellm 支援 Nebius AI Studio 的所有模型。若要使用模型,請將 model=nebius/<any-model-on-nebius-ai-studio> 設為 litellm 請求的前綴。完整的支援模型清單請參閱 https://studio.nebius.ai/ **

API 金鑰

import os
# env variable
os.environ['NEBIUS_API_KEY']

範例用法:文字生成

from litellm import completion
import os

os.environ['NEBIUS_API_KEY'] = "insert-your-nebius-ai-studio-api-key"
response = completion(
model="nebius/Qwen/Qwen3-235B-A22B",
messages=[
{
"role": "user",
"content": "What character was Wall-e in love with?",
}
],
max_tokens=10,
response_format={ "type": "json_object" },
seed=123,
stop=["\n\n"],
temperature=0.6, # either set temperature or `top_p`
top_p=0.01, # to get as deterministic results as possible
tool_choice="auto",
tools=[],
user="user",
)
print(response)

範例用法 - 串流

from litellm import completion
import os

os.environ['NEBIUS_API_KEY'] = ""
response = completion(
model="nebius/Qwen/Qwen3-235B-A22B",
messages=[
{
"role": "user",
"content": "What character was Wall-e in love with?",
}
],
stream=True,
max_tokens=10,
response_format={ "type": "json_object" },
seed=123,
stop=["\n\n"],
temperature=0.6, # either set temperature or `top_p`
top_p=0.01, # to get as deterministic results as possible
tool_choice="auto",
tools=[],
user="user",
)

for chunk in response:
print(chunk)

範例用法 - 嵌入

from litellm import embedding
import os

os.environ['NEBIUS_API_KEY'] = ""
response = embedding(
model="nebius/BAAI/bge-en-icl",
input=["What character was Wall-e in love with?"],
)
print(response)

與 LiteLLM Proxy Server 一起使用

以下說明如何透過 LiteLLM Proxy Server 呼叫 Nebius AI Studio 模型

  1. 修改 config.yaml
model_list:
- model_name: my-model
litellm_params:
model: nebius/<your-model-name> # add nebius/ prefix to use Nebius AI Studio as provider
api_key: api-key # api key to send your model
  1. 啟動 proxy
$ litellm --config /path/to/config.yaml
  1. 傳送請求到 LiteLLM Proxy Server
import openai
client = openai.OpenAI(
api_key="litellm-proxy-key", # pass litellm proxy key, if you're using virtual keys
base_url="http://0.0.0.0:4000" # litellm-proxy-base url
)

response = client.chat.completions.create(
model="my-model",
messages = [
{
"role": "user",
"content": "What character was Wall-e in love with?"
}
],
)

print(response)

支援的參數

Nebius 提供者支援下列參數:

聊天完成參數

參數類型說明
frequency_penaltynumber依據文字中出現頻率對新 tokens 施加懲罰
function_callstring/object控制模型如何呼叫函式
functionsarray函式清單,模型可為其產生 JSON 輸入
logit_biasmap修改指定 tokens 的可能性
max_tokensinteger要生成的 token 最大數量
ninteger要生成的完成數量
presence_penaltynumber依據 tokens 到目前為止是否出現在文字中對其施加懲罰
response_formatobject回應格式,例如 {"type": "json"}
seedinteger用於決定性結果的取樣種子
stopstring/arrayAPI 將停止生成 tokens 的序列
streamboolean是否串流回應
temperaturenumber控制隨機性(0-2)
top_pnumber控制 nucleus sampling
tool_choicestring/object控制要呼叫哪個函式(如果有)
toolsarray模型可使用的工具清單
userstring使用者識別碼

嵌入參數

參數類型說明
inputstring/array要嵌入的文字
userstring使用者識別碼

錯誤處理

此整合使用標準的 LiteLLM 錯誤處理。常見錯誤包括:

  • 驗證錯誤:檢查您的 API 金鑰
  • 找不到模型:請確認您使用的是有效的模型名稱
  • 速率限制錯誤:您已超過速率限制
  • 逾時錯誤:請求完成所需時間過長