快速入门

调用模型API服务

​ SCNet平台提供的模型API接口兼容 OpenAI 的接口规范,您仅需要将 base_url 、api_key 、model替换成相关需要的配置,不需要对应用做额外修改,即可无缝将您的应用切换到相应的大模型。

​ base_url:https://api.scnet.cn/api/llm/v1

​ api_key:需在模型API-API Keys进行创建,操作步骤请参考 API Key 管理。

​ model:在模型及价格查看平台提供的模型列表。

​ 本文帮助您了解并按照步骤完成 模型API 的调用,便于您了解如何通过代码使用模型能力,进而集成到您的工作或者应用中。

  • 如果您想直接体验模型能力,访问对话。
  • 如果您有模型调用经验,可以直接查看 API 参考对话补全(Chat) API。

1.获取并配置 API Key

(1)打开并登录模型API-API Key。

(2)单击创建 API Key 按钮。

(3)在弹出框的名称文本框中确认/编辑 API Key 名称,单击创建。

说明

  • API Key是请求的重要凭证,具体使用方法查看接口文档。
  • API Key用于计费统计,为了防止费用损失,请勿随意与他人共享。

2.获取 Model信息

您可查看模型列表获得平台模型信息,或者通过 模型查询接口 快速获取模型信息。

说明

  • 通过模型查询接口获取模型信息时,不消耗Tokens,不会产生费用。

3.调用API

您可以根据实际业务或者本地环境情况,选择调用模型推理服务的语言。下方样例脚本可访问 SCNet API,获得非流式输出,您可以将 stream 设置为 true 来使用流式输出。

cURL请求示例

curl 'https://api.scnet.cn/api/llm/v1/chat/completions'  \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <API Key>" \
  -d '{
        "model": "DeepSeek-R1-Distill-Qwen-7B",
        "messages": [
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Hello!"}
        ],
        "stream": false
      }'

Python请求示例

# Please install OpenAI SDK first: `pip3 install openai`

from openai import OpenAI

client = OpenAI(api_key="<API Key>", base_url="https://api.scnet.cn/api/llm/v1")

response = client.chat.completions.create(
    model="DeepSeek-R1-Distill-Qwen-7B",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"},
    ],
    stream=False
)

print(response.choices[0].message.content)

Go请求示例

package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
    "strings"
)

func main() {

    url := "https://api.scnet.cn/api/llm/v1/chat/completions"
    method := "POST"

    payload := strings.NewReader(`{
  "messages": [
    {
      "content": "You are a helpful assistant",
      "role": "system"
    },
    {
      "content": "Hi",
      "role": "user"
    }
  ],
  "model": "DeepSeek-R1-Distill-Qwen-7B",
  "stream": false
}`)
    client := &http.Client{}
    req, err := http.NewRequest(method, url, payload)

    if err != nil {
        fmt.Println(err)
        return
    }
    req.Header.Add("Content-Type", "application/json")
    req.Header.Add("Authorization", "Bearer <API Key>")

    res, err := client.Do(req)
    if err != nil {
        fmt.Println(err)
        return
    }
    defer res.Body.Close()

    body, err := ioutil.ReadAll(res.Body)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println(string(body))
}

Nodejs请求示例

// Please install OpenAI SDK first: `npm install openai`

import OpenAI from "openai";

const openai = new OpenAI({
        baseURL: 'https://api.scnet.cn/api/llm/v1',
        apiKey: '<API Key>'
});

async function main() {
  const completion = await openai.chat.completions.create({
    messages: [{ role: "system", content: "You are a helpful assistant." }],
    model: "DeepSeek-R1-Distill-Qwen-7B",
  });

  console.log(completion.choices[0].message.content);
}

main();

results matching ""

    No results matching ""