Documentation
¶
Overview ¶
Package kavel generates and edits images from Go with no API key and no account.
It calls the anonymous tier of kavel.ai, which meters its free allowance against a client id this package invents rather than an account you register, so a program using it works on a machine with nothing configured.
img, err := kavel.Generate(context.Background(), "a paper boat at sunrise", kavel.Options{AspectRatio: "16:9"})
Measured against the running service on 2026-09-07: a signed-out caller is granted 15 credits, one generated image costs 5 and one edit costs 15, so the package mints a fresh client id per call and neither lane is limited to a single run. A ceiling of 30 credits per IP per day sits above that. Free output is 1K and watermarked.
Index ¶
Constants ¶
const ( // AnonGrant is the credit balance a signed-out caller starts with. AnonGrant = 15 // CostTextToImage is what one generated image costs, so the grant pays for three. CostTextToImage = 5 // CostEdit is what one edit costs: exactly the grant, so one edit per client id. CostEdit = 15 // IPDailyCeiling caps one machine per day regardless of how many client ids it mints. IPDailyCeiling = 30 )
Free-tier facts, read out of the running service rather than estimated.
const ( // ModelGenerate is the free text-to-image engine. It takes no image input. ModelGenerate = "kavel-image-v1" // ModelEdit is the free image-to-image engine. It requires a source image. ModelEdit = "nano-banana-2-lite" )
Models reachable without an account. Anything else needs a signed-in session and returns ErrSignIn.
Variables ¶
var BaseURL = "https://www.kavel.ai"
BaseURL is the service this package talks to. It is a variable so a test or a corporate proxy can point the package somewhere else.
var ErrAuth = errors.New("kavel: invalid API key")
ErrAuth is returned when the API key is invalid or has been deleted.
var ErrQuota = errors.New("kavel: allowance spent (create an API key at https://www.kavel.ai/settings/apikeys to keep going)")
ErrQuota is returned when the free allowance is spent, either for this client id or for this machine's daily ceiling. Signing in at https://www.kavel.ai lifts the ceiling and removes the watermark.
var ErrRejected = errors.New("kavel: prompt refused")
ErrRejected is returned when the content filter refuses a prompt, or when the model fails on it. Rewording clears it; retrying the same text does not.
var ErrSignIn = errors.New("kavel: this needs a signed-in account")
ErrSignIn is returned when the request asks for something the anonymous tier does not serve — a model off the free shelf, or video, which costs more than the grant can pay at any setting.
Functions ¶
func Credits ¶
func Credits(ctx context.Context, clientID string, httpClient *http.Client) (remaining, grant int, err error)
Credits reports what the current machine and a given client id have left. It is the same read the site's own header does, and it costs nothing to call.
Pass an empty clientID to ask about a fresh identity, which is what Generate and Edit each mint per call.
Types ¶
type Image ¶
type Image struct {
// URL is a permanent, cacheable CDN link.
URL string
// Watermarked reports whether a mark was actually drawn on it. Signing in
// removes it; the field is here so a caller can tell rather than assume.
Watermarked bool
}
Image is one finished picture.
func Edit ¶
Edit rewrites an existing image. sourceURL must be a publicly reachable http(s) url and instruction says what to change ("give him a buzz cut", "put the product on a marble surface").
One edit costs the whole anonymous grant, so a fresh client id buys exactly one. This is the lane behind the hairstyle, outfit and product-photo tools on the site.
func Generate ¶
Generate turns prompt into a new image and returns it.
Naming the light, the material and the composition moves the result far more than adding adjectives: "a product photo of a mug" gives the model nothing, "matte black ceramic mug on pale oak, soft window light from the left, shallow depth of field" gives it a picture.
type Options ¶
type Options struct {
// AspectRatio is one of "1:1", "16:9", "9:16", "4:3", "3:4". Empty means
// "1:1". Ignored by Edit, which keeps the source framing.
AspectRatio string
// PollEvery is how often the job is polled. Zero means five seconds.
PollEvery time.Duration
// Timeout bounds the whole call. Zero means six minutes.
Timeout time.Duration
// HTTPClient is used for every request. Nil means http.DefaultClient.
HTTPClient *http.Client
// APIKey is a key from https://www.kavel.ai/settings/apikeys. With a key the
// call runs on your account: your credits, your plan's models, and no
// watermark on a paid plan. Empty means the KAVEL_API_KEY environment
// variable, and if that is unset too, the free anonymous tier.
APIKey string
// Model overrides the engine. Only honoured with an API key; the free tier
// has one model per lane.
Model string
}
Options tunes a single call. The zero value is valid and means a square image with a six minute deadline.