tinfoil-go currently relies on a specific feature in go-sev-guest that hasn’t been upstreamed yet. This requires adding the following line to your go.mod:
The Tinfoil Go client is a wrapper around the OpenAI Go client and provides secure communication with Tinfoil enclaves. It has the same API as the OpenAI client, with additional security features:
Automatic attestation validation to ensure enclave integrity verification
TLS certificate pinning to prevent man-in-the-middle attacks
Copy
Ask AI
package mainimport ( "context" "fmt" "log" "os" "github.com/openai/openai-go" "github.com/openai/openai-go/option" "github.com/tinfoilsh/tinfoil-go" // imported as tinfoil)func main() { // Create a client for a specific enclave and model repository client, err := tinfoil.NewClientWithParams( "enclave.example.com", "org/model-repo", option.WithAPIKey(os.Getenv("TINFOIL_API_KEY")), ) if err != nil { log.Fatal(err) } // Make requests using the OpenAI client API // Note: enclave verification happens automatically chatCompletion, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{ Messages: []openai.ChatCompletionMessageParamUnion{ openai.UserMessage("Say this is a test"), }, Model: "llama3-3-70b", // see https://docs.tinfoil.sh for supported models }) if err != nil { log.Fatal(err) } fmt.Println(chatCompletion.Choices[0].Message.Content)}
// 1. Create a clientclient, err := tinfoil.NewClientWithParams( "enclave.example.com", // Enclave hostname "org/repo", // GitHub repository option.WithAPIKey(os.Getenv("TINFOIL_API_KEY")),)if err != nil { log.Fatal(err)}// 2. Use client as you would openai.Client // see https://pkg.go.dev/github.com/openai/openai-go for API documentation
This library is a drop-in replacement for the official OpenAI Go client that can be used with Tinfoil. All methods and types are identical. See the OpenAI Go client documentation for complete API usage and documentation.