加载中
加载中
三步:获取密钥、充值额度、发送首个请求。该 API 遵循 OpenAI 协议——在官方 SDK 中,唯一需要改动的是 base_url。
https://llmproxy.org/v1。在 Authorization: Bearer sk-max-… 请求头中传入密钥。将其保存在环境变量中,不要把密钥写入代码或仓库。
from openai import OpenAIimport os client = OpenAI( base_url="https://llmproxy.org/v1", api_key=os.environ["LLMPROXY_API_KEY"],)
在 model 字段中传入来自 模型目录 的 id,或来自 GET https://llmproxy.org/v1/models 的 id。示例使用了目录中最便宜的聊天模型。
from openai import OpenAIimport os client = OpenAI( base_url="https://llmproxy.org/v1", # the only difference from OpenAI api_key=os.environ["MAXAI_API_KEY"],) resp = client.chat.completions.create( model="mistralai/mistral-nemo", messages=[{"role": "user", "content": "Explain what an API gateway is in two sentences."}], stream=True,)for chunk in resp: print(chunk.choices[0].delta.content or "", end="")
user。