package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
}
type Request struct {
Messages []Message `json:"messages"`
MaxCostPerCall float64 `json:"max_cost_per_call"`
}
func main() {
req := Request{
Messages: []Message{
{Role: "user", Content: "Hello, world!"},
},
MaxCostPerCall: 0.01,
}
jsonData, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST",
"https://api.withperf.pro/v1/chat",
bytes.NewBuffer(jsonData))
httpReq.Header.Set("Authorization", "Bearer pk_test_your_key_here")
httpReq.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(httpReq)
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println("Response:", result["output"])
fmt.Println("Cost:", result["billing"].(map[string]interface{})["cost_usd"])
}