← Quickstart

Go quickstart

Go 1.21+. stdlib net/http only — no third-party SDK required.

1. Setup

// main.go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
    "os"
)

const edgifyAPI = "https://api.edgify.net"

func token() string { return os.Getenv("EDGIFY_TOKEN") }

2. Mint a virtual key

func mintVK(providerKeyID, limitProfileID string) (id, secret string, err error) {
    body, _ := json.Marshal(map[string]string{
        "name":             "go-quickstart",
        "provider_key_id":  providerKeyID,
        "limit_profile_id": limitProfileID,
    })
    req, _ := http.NewRequest("POST", edgifyAPI+"/api/virtual-keys", bytes.NewReader(body))
    req.Header.Set("authorization", "Bearer "+token())
    req.Header.Set("content-type", "application/json")
    res, err := http.DefaultClient.Do(req)
    if err != nil { return "", "", err }
    defer res.Body.Close()
    var out struct { ID, TokenOneTime string `json:"token_one_time"` }
    if err := json.NewDecoder(res.Body).Decode(&out); err != nil { return "", "", err }
    return out.ID, out.TokenOneTime, nil
}

3. Use it

body, _ := json.Marshal(map[string]any{
    "model":    "gpt-4o-mini",
    "messages": []map[string]string{{"role": "user", "content": "hi"}},
})
req, _ := http.NewRequest("POST",
    "https://proxy.edgify.net/v1/chat/completions",
    bytes.NewReader(body),
)
req.Header.Set("authorization", "Bearer "+vkToken)
req.Header.Set("content-type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
fmt.Println(res.Status)