OpenAI聊天格式

Gemini 图片生成

POST/v1/chat/completions

OpenAI聊天格式

Gemini 图片生成

鉴权: 使用 Bearer Token 认证。 格式: `Authorization: Bearer sk-xxxxxx`

请求体

Content-Type: application/json

字段类型必填说明
modelstring是
streamboolean是
messagesarray<object>是
[]object
rolestring
contentstring
extra_bodyobject
googleobject是
image_configobject是
aspect_ratiostring是
image_sizestring是
contentsarray<object>是
[]object
rolestring
partsarray<object>
[]object
textstring

示例代码

curl -X POST "https://api.nodeprice.com/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
  "model": "string",
  "stream": false,
  "messages": [
    {
      "role": "string",
      "content": "string"
    }
  ],
  "extra_body": {
    "google": {
      "image_config": {
        "aspect_ratio": "string",
        "image_size": "string"
      }
    }
  },
  "contents": [
    {
      "role": "string",
      "parts": [
        {
          "text": "string"
        }
      ]
    }
  ]
}'
const url = "https://api.nodeprice.com/v1/chat/completions";
const body = {
  "model": "string",
  "stream": false,
  "messages": [
    {
      "role": "string",
      "content": "string"
    }
  ],
  "extra_body": {
    "google": {
      "image_config": {
        "aspect_ratio": "string",
        "image_size": "string"
      }
    }
  },
  "contents": [
    {
      "role": "string",
      "parts": [
        {
          "text": "string"
        }
      ]
    }
  ]
};

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
  },
  body: JSON.stringify(body)
});

console.log(await response.text());
package main

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

func main() {
	url := "https://api.nodeprice.com/v1/chat/completions"
	body := strings.NewReader(`{
  "model": "string",
  "stream": false,
  "messages": [
    {
      "role": "string",
      "content": "string"
    }
  ],
  "extra_body": {
    "google": {
      "image_config": {
        "aspect_ratio": "string",
        "image_size": "string"
      }
    }
  },
  "contents": [
    {
      "role": "string",
      "parts": [
        {
          "text": "string"
        }
      ]
    }
  ]
}`)
	req, err := http.NewRequest("POST", url, body)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer <token>")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	data, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(data))
}
import requests

url = "https://api.nodeprice.com/v1/chat/completions"

body = """{
  "model": "string",
  "stream": false,
  "messages": [
    {
      "role": "string",
      "content": "string"
    }
  ],
  "extra_body": {
    "google": {
      "image_config": {
        "aspect_ratio": "string",
        "image_size": "string"
      }
    }
  },
  "contents": [
    {
      "role": "string",
      "parts": [
        {
          "text": "string"
        }
      ]
    }
  ]
}"""

response = requests.request("POST", url, data=body, headers={
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
})

print(response.text)
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n"
    + "  \"model\": \"string\",\n"
    + "  \"stream\": false,\n"
    + "  \"messages\": [\n"
    + "    {\n"
    + "      \"role\": \"string\",\n"
    + "      \"content\": \"string\"\n"
    + "    }\n"
    + "  ],\n"
    + "  \"extra_body\": {\n"
    + "    \"google\": {\n"
    + "      \"image_config\": {\n"
    + "        \"aspect_ratio\": \"string\",\n"
    + "        \"image_size\": \"string\"\n"
    + "      }\n"
    + "    }\n"
    + "  },\n"
    + "  \"contents\": [\n"
    + "    {\n"
    + "      \"role\": \"string\",\n"
    + "      \"parts\": [\n"
    + "        {\n"
    + "          \"text\": \"string\"\n"
    + "        }\n"
    + "      ]\n"
    + "    }\n"
    + "  ]\n"
    + "}");
Request request = new Request.Builder()
    .url("https://api.nodeprice.com/v1/chat/completions")
    .method("POST", body)
    .addHeader("Content-Type", "application/json")
    .addHeader("Authorization", "Bearer <token>")
    .build();

Response response = client.newCall(request).execute();
System.out.println(response.body().string());
#include <stdio.h>
#include <curl/curl.h>

int main(void) {
    CURL *curl = curl_easy_init();
    if (curl == NULL) {
        return 1;
    }

    struct curl_slist *headers = NULL;
    headers = curl_slist_append(headers, "Content-Type: application/json");
    headers = curl_slist_append(headers, "Authorization: Bearer <token>");

    curl_easy_setopt(curl, CURLOPT_URL, "https://api.nodeprice.com/v1/chat/completions");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\n"
        + "  \"model\": \"string\",\n"
        + "  \"stream\": false,\n"
        + "  \"messages\": [\n"
        + "    {\n"
        + "      \"role\": \"string\",\n"
        + "      \"content\": \"string\"\n"
        + "    }\n"
        + "  ],\n"
        + "  \"extra_body\": {\n"
        + "    \"google\": {\n"
        + "      \"image_config\": {\n"
        + "        \"aspect_ratio\": \"string\",\n"
        + "        \"image_size\": \"string\"\n"
        + "      }\n"
        + "    }\n"
        + "  },\n"
        + "  \"contents\": [\n"
        + "    {\n"
        + "      \"role\": \"string\",\n"
        + "      \"parts\": [\n"
        + "        {\n"
        + "          \"text\": \"string\"\n"
        + "        }\n"
        + "      ]\n"
        + "    }\n"
        + "  ]\n"
        + "}");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

    CURLcode code = curl_easy_perform(curl);
    if (code != CURLE_OK) {
        fprintf(stderr, "%s\n", curl_easy_strerror(code));
    }

    curl_slist_free_all(headers);
    curl_easy_cleanup(curl);
    return 0;
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var client = new HttpClient();
        var request = new HttpRequestMessage(HttpMethod.Post, "https://api.nodeprice.com/v1/chat/completions");
        request.Headers.Add("Authorization", "Bearer <token>");
        request.Content = new StringContent("{\n"
            + "  \"model\": \"string\",\n"
            + "  \"stream\": false,\n"
            + "  \"messages\": [\n"
            + "    {\n"
            + "      \"role\": \"string\",\n"
            + "      \"content\": \"string\"\n"
            + "    }\n"
            + "  ],\n"
            + "  \"extra_body\": {\n"
            + "    \"google\": {\n"
            + "      \"image_config\": {\n"
            + "        \"aspect_ratio\": \"string\",\n"
            + "        \"image_size\": \"string\"\n"
            + "      }\n"
            + "    }\n"
            + "  },\n"
            + "  \"contents\": [\n"
            + "    {\n"
            + "      \"role\": \"string\",\n"
            + "      \"parts\": [\n"
            + "        {\n"
            + "          \"text\": \"string\"\n"
            + "        }\n"
            + "      ]\n"
            + "    }\n"
            + "  ]\n"
            + "}", Encoding.UTF8, "application/json");

        var response = await client.SendAsync(request);
        Console.WriteLine(await response.Content.ReadAsStringAsync());
    }
}

响应

200 成功

Content-Type: application/json

字段类型必填说明
idstring是
modelstring是
objectstring是
createdinteger是
choicesarray<object>是
[]object
indexinteger
messageobject
rolestring是
contentstring是
finish_reasonstring
usageobject是
prompt_tokensinteger是
completion_tokensinteger是
total_tokensinteger是