OpenAI
1. 概述
2. 请求说明
3. 请求参数
3.1 Header 参数
参数名称
类型
必填
说明
示例值
3.2 Body 参数 (application/json)
参数名称
类型
必填
说明
示例
4. 请求示例
5. 响应示例
最后更新于
最后更新于
POST /v1/embeddings
Content-Type: application/json
Accept: application/json
Authorization: Bearer $YOUR_API_KEY
{
"model": "text-embedding-ada-002",
"input": "今天天气怎么样"
}curl https://gateway.theturbo.ai/v1/embeddings \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-d "{
\"model\": \"text-embedding-ada-002\",
\"input\": \"今天天气怎么样\"
}"package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
const (
YOUR_API_KEY = "sk-123456789012345678901234567890123456789012345678"
REQUEST_PAYLOAD = `{
"model": "text-embedding-ada-002",
"input": "今天天气怎么样"
}`
)
func main() {
requestURL := "https://gateway.theturbo.ai/v1/embeddings"
requestMethod := "POST"
requestPayload := strings.NewReader(REQUEST_PAYLOAD)
req, err := http.NewRequest(requestMethod, requestURL, requestPayload)
if err != nil {
fmt.Println("Create request failed, err: ", err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
req.Header.Add("Authorization", "Bearer "+YOUR_API_KEY)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Do request failed, err: ", err)
return
}
defer resp.Body.Close()
respBodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Read response body failed, err: ", err)
return
}
fmt.Println(string(respBodyBytes))
}{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
.... (1536 floats total for ada-002)
-0.0028842222,
],
"index": 0
}
],
"model": "text-embedding-ada-002",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}