cheapaimodel
cheapaimodel is an OpenAI-compatible LLM gateway. One API key gives access to models from DeepSeek, Z.ai (GLM), Moonshot (Kimi) and xAI (Grok), billed per token from a prepaid USD balance.
Setup
go get github.com/zendev-sh/goai@latestimport "github.com/zendev-sh/goai/provider/cheapaimodel"Set the CHEAPAIMODEL_API_KEY environment variable, or pass WithAPIKey() directly. Create a key at console.cheapaimodel.ai/keys.
Models
Model IDs are bare names:
| Model ID | Context | Image input |
|---|---|---|
deepseek-v4-1-flash | 1M | Yes |
glm-5.3 | 1M | No |
glm-5.3-flash | 1M | Yes |
grok-4.7 | 500K | Yes |
kimi-k3 | 1M | Yes |
GET https://cheapaimodel.ai/api/models lists the current catalog with prices and needs no API key. See cheapaimodel.ai/models and cheapaimodel.ai/docs for details.
Tested Models
Unit tested (mock HTTP server): deepseek-v4-1-flash, glm-5.3, kimi-k3
Live tested (real API, 2026-11-03): all five models above with GenerateText, StreamText and a tool loop (GenerateText and StreamText with MaxSteps), image input on the four models that accept it, and GenerateObject (see the glm-5.3 note below).
Usage
model := cheapaimodel.Chat("deepseek-v4-1-flash")
result, err := goai.GenerateText(ctx, model, goai.WithPrompt("Hello"))
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Text)Options
| Option | Type | Description |
|---|---|---|
WithAPIKey(key) | string | Set a static API key |
WithTokenSource(ts) | provider.TokenSource | Set a dynamic token source |
WithBaseURL(url) | string | Override the default https://api.cheapaimodel.ai/v1 endpoint |
WithHeaders(h) | map[string]string | Set additional HTTP headers |
WithHTTPClient(c) | *http.Client | Set a custom *http.Client |
Notes
- Declares text-only chat capability with tool calling. Image parts are sent in the standard
image_urlformat for models that accept them. - The models can return reasoning text, surfaced as
result.Reasoning. Reasoning from earlier assistant turns is sent back asreasoning_content, and streaming requests setstream_options.include_usageso the final chunk carries token usage. kimi-k3only acceptstemperature1 or 0.6 andtop_p0.95. Other values return HTTP 400invalid_parameter_error; leave them unset or use those values.glm-5.3often answers in plain text instead of following the JSON schema thatGenerateObjectsends (1 of 5 attempts parsed in testing;glm-5.3-flash4 of 5, the other three models 5 of 5).result.Response.Modelcan be the upstream model name (for exampledeepseek-v4.1-flash-1017) rather than the ID you passed.- The package provides
Chatonly. cheapaimodel has no embeddings models. - Environment variable
CHEAPAIMODEL_BASE_URLcan override the default endpoint.