Skip to main content

API reference

请求接口时将 url 设置为我们的API地址:https://reone.proai520.com

只要支持设置openai的API地址(BaseUrl)的应用基本都是支持的。

部分应用需要在Api地址后面添加/v1、/v1/chat/completions 等后缀,请注意自己使用的应用的帮助说明

test.py
  import urllib.request
import urllib.error
import json

def chat_with_gpt4o(prompt):
# 替换为你的 OpenAI API 密钥
api_key = "sk-xxxx"

# OpenAI API 端点
url = "https://reone.proai520.com/v1/chat/completions"

# 请求头
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}

# 请求体
data = {
"model": "grok-3-fast",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
],
"temperature": 0.7,
"max_tokens": 5000
}

# 将数据编码为 JSON 格式
data_encoded = json.dumps(data).encode("utf-8")

try:
# 创建请求对象
req = urllib.request.Request(url, data=data_encoded, headers=headers, method="POST")

# 发送请求并获取响应
with urllib.request.urlopen(req) as response:
response_data = response.read()
response_json = json.loads(response_data.decode("utf-8"))

# 提取模型的回复
return response_json["choices"][0]["message"]["content"]
except urllib.error.URLError as e:
return f"Error: {str(e)}"
except Exception as e:
return f"Error: {str(e)}"


# 示例:与 大模型 对话
if __name__ == "__main__":
user_input = "今天几号?"
print("User:", user_input)

response = chat_with_gpt4o(user_input)
print("AI :", response)