Skip to content
Sign In Get Started

Go

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.

Terminal window
go get github.com/sashabaranov/go-openai
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.

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)
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)
}

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 wrapper
type 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 = httpClient
client := openai.NewClientWithConfig(config)
HeaderDescription
Floopy-CacheCache strategy: semantic or exact
floopy-property-*Attach custom metadata for filtering in the dashboard
floopy-fallbackFallback model if the primary provider fails
floopy-session-idGroup related requests into a session
floopy-user-idAssociate requests with an end user

See the Headers Reference for the full list.