Go
Overview
Floopy is a zero-SDK gateway. The popular go-openai package supports custom base URLs, so you can route all requests through Floopy without any extra dependencies. You get caching, rate limiting, fallbacks, and observability for free.
Installation
go get github.com/sashabaranov/go-openaiConfiguration
package main
import ( openai "github.com/sashabaranov/go-openai")
func main() { config := openai.DefaultConfig("fp_your_api_key") config.BaseURL = "https://api.floopy.ai/v1"
client := openai.NewClientWithConfig(config)}Set your Floopy API key (starts with fp_). You can create one in the dashboard.
Basic Request
resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ Model: openai.GPT4o, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, Content: "Explain quantum computing in one sentence.", }, }, },)if err != nil { log.Fatal(err)}
fmt.Println(resp.Choices[0].Message.Content)Streaming
stream, err := client.CreateChatCompletionStream( context.Background(), openai.ChatCompletionRequest{ Model: openai.GPT4o, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, Content: "Write a short poem.", }, }, Stream: true, },)if err != nil { log.Fatal(err)}defer stream.Close()
for { response, err := stream.Recv() if errors.Is(err, io.EOF) { break } if err != nil { log.Fatal(err) } fmt.Print(response.Choices[0].Delta.Content)}Custom Headers
Add Floopy-specific headers by setting a custom HTTP transport or using the Header field on the config:
config := openai.DefaultConfig("fp_your_api_key")config.BaseURL = "https://api.floopy.ai/v1"
// Add custom headers via a round-tripper wrappertype headerTransport struct { base http.RoundTripper headers map[string]string}
func (t *headerTransport) RoundTrip(req *http.Request) (*http.Response, error) { for k, v := range t.headers { req.Header.Set(k, v) } return t.base.RoundTrip(req)}
httpClient := &http.Client{ Transport: &headerTransport{ base: http.DefaultTransport, headers: map[string]string{ "Floopy-Cache": "semantic", "floopy-property-environment": "production", "floopy-fallback": "claude-sonnet-4-20250514", }, },}
config.HTTPClient = httpClientclient := openai.NewClientWithConfig(config)| Header | Description |
|---|---|
Floopy-Cache | Cache strategy: semantic or exact |
floopy-property-* | Attach custom metadata for filtering in the dashboard |
floopy-fallback | Fallback model if the primary provider fails |
floopy-session-id | Group related requests into a session |
floopy-user-id | Associate requests with an end user |
See the Headers Reference for the full list.