curl -X POST "http://localhost:8080/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Get capital info"}],"response_format":{"type":"json_schema","json_schema":{"name":"capital_info","strict":true,"schema":{"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}}}}'
const response = await fetch(
"http://localhost:8080/v1/chat/completions",
{
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
messages: [{ role: "user", content: "Get capital info" }],
response_format: {
type: "json_schema",
json_schema: {
name: "capital_info",
strict: true,
schema: {
type: "object",
properties: { name: { type: "string" } },
required: ["name"]
}
}
}
})
}
);
const data = await response.json();
console.log(data);
import requests
url = "http://localhost:8080/v1/chat/completions"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
payload = {
"messages": [{"role": "user", "content": "Get capital info"}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "capital_info",
"strict": True,
"schema": {
"type": "object",
"properties": {"name": {"type": "string"}},
"required": ["name"]
}
}
}
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{"messages":[{"role":"user","content":"Get capital info"}],"response_format":{"type":"json_schema","json_schema":{"name":"capital_info","strict":true,"schema":{"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}}}}`)
url := "http://localhost:8080/v1/chat/completions"
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(payload))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}