Go integration guide

Go prompt compression

Go is increasingly popular for building high-performance AI backends. SuperCompress's REST API makes it easy to add prompt compression to any Go service.

By Arjun Shah - Creator of SuperCompress - Updated 2026-07-03

Go client implementation

package supercompress

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

type CompressRequest struct {
    Context string `json:"context"`
    Query   string `json:"query"`
}

type CompressResponse struct {
    CompressedText string `json:"compressed_text"`
}

func Compress(apiKey, context, query string) (string, error) {
    body := CompressRequest{Context: context, Query: query}
    buf := new(bytes.Buffer)
    json.NewEncoder(buf).Encode(body)

    req, _ := http.NewRequest("POST",
        "https://supercompress.dev/api/v1/compress", buf)
    req.Header.Set("X-API-Key", apiKey)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil { return "", err }
    defer resp.Body.Close()

    var result CompressResponse
    json.NewDecoder(resp.Body).Decode(&result)
    return result.CompressedText, nil
}

Frequently asked questions

Does this require the Python package?

No. Go services use the REST API directly. No Python dependency needed.

How fast is the Go integration?

The REST API responds in ~60ms. The Go HTTP client adds minimal overhead (~2-5ms).

Try it yourself

Paste your long prompt into the playground, ask a question, and see what SuperCompress keeps and removes. Free, no signup needed.

Open the Playground Embed the badge