Skip to content

👋快速开始

本篇教程中我们将介绍如何使用SparkU AI平台注册账号

充值余额和创建一个apiKey以及快速使用主流编程语言实现调用API智能问答

建议使用Chrome浏览器进行操作,推荐使用Postman进行接口调试

注册账号

  1. 打开注册页面:https://ai.sparku.net/register

  2. 输入你的用户信息和密码,填写邮箱获取验证码

    注意:邮箱仅支持以下后缀:@qq.com @163.com @126.com @gmail.com @outlook.com yeah.net

    img.png

充值

  1. 注册完成后前往登录页面登录你的账号:https://ai.sparku.net/login
  2. 登录后进入Dashboard控制台,选择余额充值:https://ai.sparku.net/topup
  3. 按照页面提示选择输入你的充值金额,选择支付方式,确认充值,充值成功后,即可看到充值金额,具体的充值优惠请以实际页面显示为准 img.png

创建密钥

  1. 打开页面左侧的API令牌部分
  2. 点击底部的创建令牌 img.png
  3. 根据你的实际需求填写密钥的信息 img.png 底部的分组部分如果无特殊需求可以选择默认分组,如果你想了解有关分组的更多信息,请查看文档:分组介绍
  4. 创建完成后你可以在主页复制创建好的apiKey,并将其用于你的工作流中 img.png

快速调用

以下仅为调用的简单示例,你可以根据你的技术栈、业务需求和实际用途进行扩展以及使用

你可以将代码中的Authorization中的Bearer后面以sk开头的密钥替换为你的密钥

Python

python
import requests
import json

url = "https://ai.sparku.net/v1/chat/completions"

payload = json.dumps({
  "model": "gpt-4o-mini",
  "messages": [
    {
      "role": "user",
      "content": "请介绍一下你自己"
    }
  ],
  "temperature": 0.7
})
headers = {
  'Authorization': 'Bearer sk-please-replace-with-your-key',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

cURL

bash
curl --location 'https://ai.sparku.net/v1/chat/completions' \
--header 'Authorization: Bearer sk-please-replace-with-your-key' \
--header 'Content-Type: application/json' \
--data '{
    "model": "gpt-4o-mini",
    "messages": [{"role":"user","content":"请介绍一下你自己"}],
    "temperature": 0.7
}'

Wget

bash
wget --no-check-certificate --quiet \
  --method POST \
  --timeout=0 \
  --header 'Authorization: Bearer sk-please-replace-with-your-key' \
  --header 'Content-Type: application/json' \
  --body-data '{
    "model": "gpt-4o-mini",
    "messages": [{"role":"user","content":"请介绍一下你自己"}],
    "temperature": 0.7
}' \
   'https://ai.sparku.net/v1/chat/completions'

Javascript

javascript
const axios = require('axios');
let data = JSON.stringify({
    "model": "gpt-4o-mini",
    "messages": [
        {
            "role": "user",
            "content": "请介绍一下你自己"
        }
    ],
    "temperature": 0.7
});

let config = {
    method: 'post',
    maxBodyLength: Infinity,
    url: 'https://ai.sparku.net/v1/chat/completions',
    headers: {
        'Authorization': 'Bearer sk-please-replace-with-your-key',
        'Content-Type': 'application/json'
    },
    data: data
};

axios.request(config)
    .then((response) => {
        console.log(JSON.stringify(response.data));
    })
    .catch((error) => {
        console.log(error);
    });

Typescript

typescript

Java

java
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n    \"model\": \"gpt-4o-mini\",\r\n    \"messages\": [{\"role\":\"user\",\"content\":\"请介绍一下你自己\"}],\r\n    \"temperature\": 0.7\r\n}");
Request request = new Request.Builder()
  .url("https://ai.sparku.net/v1/chat/completions")
  .method("POST", body)
  .addHeader("Authorization", "Bearer sk-please-replace-with-your-key")
  .addHeader("Content-Type", "application/json")
  .build();
Response response = client.newCall(request).execute();

Go

go
package main

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

func main() {

  url := "https://ai.sparku.net/v1/chat/completions"
  method := "POST"

  payload := strings.NewReader(`{`+"
"+`
    "model": "gpt-4o-mini",`+"
"+`
    "messages": [{"role":"user","content":"请介绍一下你自己"}],`+"
"+`
    "temperature": 0.7`+"
"+`
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Authorization", "Bearer sk-please-replace-with-your-key")
  req.Header.Add("Content-Type", "application/json")

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

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

PHP

php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://ai.sparku.net/v1/chat/completions',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "model": "gpt-4o-mini",
    "messages": [{"role":"user","content":"请介绍一下你自己"}],
    "temperature": 0.7
}',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer sk-please-replace-with-your-key',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Rust

rust
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::builder()
        .build()?;

    let mut headers = reqwest::header::HeaderMap::new();
    headers.insert("Authorization", "Bearer sk-please-replace-with-your-key".parse()?);
    headers.insert("Content-Type", "application/json".parse()?);

    let data = r#"{
    "model": "gpt-4o-mini",
    "messages": [
        {
            "role": "user",
            "content": "请介绍一下你自己"
        }
    ],
    "temperature": 0.7
}"#;

    let json: serde_json::Value = serde_json::from_str(&data)?;

    let request = client.request(reqwest::Method::POST, "https://ai.sparku.net/v1/chat/completions")
        .headers(headers)
        .json(&json);

    let response = request.send().await?;
    let body = response.text().await?;

    println!("{}", body);

    Ok(())
}

C

c
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
  curl_easy_setopt(curl, CURLOPT_URL, "https://ai.sparku.net/v1/chat/completions");
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
  struct curl_slist *headers = NULL;
  headers = curl_slist_append(headers, "Authorization: Bearer sk-please-replace-with-your-key");
  headers = curl_slist_append(headers, "Content-Type: application/json");
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  const char *data = "{\r\n    \"model\": \"gpt-4o-mini\",\r\n    \"messages\": [{\"role\":\"user\",\"content\":\"请介绍一下你自己\"}],\r\n    \"temperature\": 0.7\r\n}";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
  res = curl_easy_perform(curl);
  curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);

Swift

swift
let parameters = "{\r\n    \"model\": \"gpt-4o-mini\",\r\n    \"messages\": [{\"role\":\"user\",\"content\":\"请介绍一下你自己\"}],\r\n    \"temperature\": 0.7\r\n}"
let postData = parameters.data(using: .utf8)

var request = URLRequest(url: URL(string: "https://ai.sparku.net/v1/chat/completions")!,timeoutInterval: Double.infinity)
request.addValue("Bearer sk-please-replace-with-your-key", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

request.httpMethod = "POST"
request.httpBody = postData

let task = URLSession.shared.dataTask(with: request) { data, response, error in 
  guard let data = data else {
    print(String(describing: error))
    return
  }
  print(String(data: data, encoding: .utf8)!)
}

task.resume()

SparkU AI Platform | 使用协议  隐私政策
本站API仅用于测试和体验目的,请自觉遵守知识版权法规,切勿用于非法用途。本站不承担任何法律责任。