Documentation
¶
Overview ¶
Package crossmodel is the cross-model API compatibility suite for #138: one request shape, sent to every major model family over both the OpenAI-compatible /v1/chat/completions and the Anthropic-compatible /v1/messages surface, with the SSE chunk layout, tool-call serialization, structured output and error-envelope contracts asserted on each response.
The live suite is env-gated (HANZO_API_KEY) so it skips in a gate that has no credential, and its contract checks run against an httptest server so CI still proves the checks themselves work. See qa/crossmodel/README.md.
Index ¶
- Constants
- Variables
- func BaseURL() string
- func CheckAnthropicErrorEnvelope(raw []byte) []string
- func CheckAnthropicMessage(raw []byte) []string
- func CheckAnthropicStream(frames []Frame) []string
- func CheckJSONObjectContent(raw []byte, requiredKeys ...string) []string
- func CheckOpenAIChatCompletion(raw []byte) []string
- func CheckOpenAIErrorEnvelope(raw []byte) []string
- func CheckOpenAIStream(frames []Frame) []string
- func CheckOpenAIStreamToolCalls(frames []Frame) []string
- func CheckOpenAIToolCalls(raw []byte, wantNames []string, minCalls int) []string
- func WriteReport(path string, cells []Cell) error
- type Cell
- type Client
- func (c *Client) Chat(ctx context.Context, body any) (*Reply, error)
- func (c *Client) ChatStream(ctx context.Context, body any) (*Reply, error)
- func (c *Client) Messages(ctx context.Context, body any) (*Reply, error)
- func (c *Client) MessagesStream(ctx context.Context, body any) (*Reply, error)
- func (c *Client) Models(ctx context.Context) (*Reply, error)
- func (c *Client) Post(ctx context.Context, path string, body any, hdr map[string]string) (*Reply, error)
- func (c *Client) PostStream(ctx context.Context, path string, body any, hdr map[string]string) (*Reply, error)
- type Family
- type Frame
- type Reply
- type Scenario
Constants ¶
const ( BaseURLEnv = "HANZO_API_URL" KeyEnv = "HANZO_API_KEY" // ReportEnv names a path to write the matrix report to (JSON; the .md twin is // written beside it). Unset means no artifact. ReportEnv = "HANZO_QA_REPORT" // LivePublicEnv opts the key-free public-surface checks into real network calls. // They are off by default so a gate without egress stays green. LivePublicEnv = "HANZO_QA_LIVE" )
BaseURLEnv and KeyEnv are the two inputs the live suite needs.
const AnthropicVersion = "2023-06-01"
AnthropicVersion is sent on /v1/messages. The gateway defaults it when absent, but a compatibility suite should not rely on a default it did not ask for.
const DefaultBase = "https://api.hanzo.ai"
DefaultBase is the production gateway. HANZO_API_URL may name the URL with or without the /v1 suffix (the docs print it without).
const PlainPrompt = "Name one primary color. Answer in one short sentence."
PlainPrompt is the one question every family answers on every sync/stream cell.
const RequestTimeout = 150 * time.Second
RequestTimeout bounds one model round trip. Reasoning families stream for a while before they answer, so this is generous by design; the whole suite still fails fast because every scenario runs with its own context.
Variables ¶
var JSONKeys = []string{"name", "age", "tags"}
JSONKeys are the fields a structured-output answer must carry.
var Matrix = []Family{ {Name: "Zen", Model: "hanzo/zen", Chat: true}, {Name: "Enso", Model: "enso-flash", Chat: true}, {Name: "Kai", Model: "hanzo/kai"}, {Name: "Claude", Model: "anthropic/claude-haiku-4.5", Chat: true, Tools: true}, {Name: "GPT", Model: "openai/gpt-4o-mini", Chat: true, Tools: true}, {Name: "Gemini", Model: "google/gemini-2.5-flash-lite", Chat: true, Tools: true}, {Name: "Qwen", Model: "qwen/qwen-plus", Chat: true, Tools: true}, {Name: "DeepSeek", Model: "deepseek/deepseek-v4-flash", Chat: true, Tools: true}, {Name: "Llama", Model: "meta-llama/llama-3.3-70b-instruct", Chat: true, Tools: true}, }
Matrix pins one representative per family named in #138. The ids are taken from the live catalog (2026-11), so a rename surfaces as a 404 model_not_found in the suite rather than drifting silently out of coverage.
Kai is listed with Chat=false on purpose: the catalog routes it to /v1/decisions, so an identical chat payload cannot reach it at all. That is a matrix finding, not a test bug — see README.md.
var Scenarios = []Scenario{ {Name: "openai_sync", NeedsChat: true, Run: openAISync}, {Name: "openai_stream", NeedsChat: true, Run: openAIStream}, {Name: "openai_tools", NeedsChat: true, NeedsTools: true, Run: openAITools}, {Name: "openai_tools_parallel", NeedsChat: true, NeedsTools: true, Run: openAIParallelTools}, {Name: "openai_tool_followup", NeedsChat: true, NeedsTools: true, Run: openAIToolFollowUp}, {Name: "openai_json_object", NeedsChat: true, Run: openAIJSONObject}, {Name: "openai_json_schema", NeedsChat: true, Run: openAIJSONSchema}, {Name: "openai_stream_tools", NeedsChat: true, NeedsTools: true, Run: openAIStreamTools}, {Name: "anthropic_sync", NeedsChat: true, Run: anthropicSync}, {Name: "anthropic_stream", NeedsChat: true, Run: anthropicStream}, }
Scenarios is the coverage set named in #138: sync, streaming SSE layout, tool calls (single, parallel, and the multi-turn role:"tool" follow-up), structured output in both json_object and json_schema form, on both API shapes.
Functions ¶
func CheckAnthropicErrorEnvelope ¶
CheckAnthropicErrorEnvelope asserts the Anthropic error contract: {type:"error", error:{type,message}} with a documented error type.
func CheckAnthropicMessage ¶
CheckAnthropicMessage asserts the sync /v1/messages contract.
func CheckAnthropicStream ¶
CheckAnthropicStream asserts the Anthropic SSE contract: the documented event sequence arrives in order, every payload names its own event type, at least one text_delta carries text, and message_stop closes the stream.
func CheckJSONObjectContent ¶
CheckJSONObjectContent asserts that the assistant message is parseable JSON: the response_format json_object / json_schema contract. requiredKeys are only checked when given (the json_schema case).
func CheckOpenAIChatCompletion ¶
CheckOpenAIChatCompletion asserts the sync /v1/chat/completions contract.
func CheckOpenAIErrorEnvelope ¶
CheckOpenAIErrorEnvelope asserts the OpenAI error contract: {error:{message,type, param,code}}. It also names the gateway's own {status,msg,data,data2} envelope when that is what came back, because every SDK parsing this endpoint reads error.message and nothing else.
func CheckOpenAIStream ¶
CheckOpenAIStream asserts the OpenAI SSE contract over the frames that arrived: every payload is a chat.completion.chunk, at least one carries delta.content, the last data payload before the sentinel carries a valid finish_reason, and the stream ends with exactly `data: [DONE]`.
func CheckOpenAIStreamToolCalls ¶
CheckOpenAIStreamToolCalls reassembles delta.tool_calls fragments the way a client must, and asserts the stream serializes complete, parseable calls. This is where a provider that splits arguments across chunks without an index, or emits truncated JSON, gets caught.
func CheckOpenAIToolCalls ¶
CheckOpenAIToolCalls asserts the sync tool-call contract: finish_reason tool_calls, and wantCount calls each with an id, type function, a name from the requested set, and arguments that serialize to a JSON object.
func WriteReport ¶
WriteReport drops the matrix as JSON at path and a markdown twin beside it, so a CI run can publish both without post-processing.
Types ¶
type Cell ¶
type Cell struct {
Family string `json:"family"`
Model string `json:"model"`
Scenario string `json:"scenario"`
Status int `json:"status"`
Result string `json:"result"` // pass | fail | skip
Problems []string `json:"problems,omitempty"`
Detail string `json:"detail,omitempty"`
}
Cell is one family x scenario outcome of the matrix.
type Client ¶
type Client struct {
Base string // gateway root ending in /v1
Key string // Bearer credential; empty means send no Authorization at all
HTTP *http.Client
}
Client speaks both wire formats of the gateway: it posts an OpenAI-shaped body to /v1/chat/completions and an Anthropic-shaped one to /v1/messages, and reads either a JSON answer or an SSE stream. It is deliberately tiny — the suite's job is the response contract, not a full SDK.
func NewClient ¶
func NewClient() *Client
NewClient builds a client from the environment (see BaseURL and KeyEnv).
func (*Client) ChatStream ¶
ChatStream posts a streaming OpenAI payload with "stream": true already set by the caller.
func (*Client) MessagesStream ¶
MessagesStream posts a streaming Anthropic payload with "stream": true set by the caller.
func (*Client) Models ¶
Models reads the public catalog, which is the source of the capability flags the matrix skips on.
func (*Client) Post ¶
func (c *Client) Post(ctx context.Context, path string, body any, hdr map[string]string) (*Reply, error)
Post sends body to base+path and returns the whole JSON answer.
func (*Client) PostStream ¶
func (c *Client) PostStream(ctx context.Context, path string, body any, hdr map[string]string) (*Reply, error)
PostStream sends a streaming request and returns every SSE frame in order. A response that is not an event stream (an error envelope, say) comes back with its Body set and no frames, which is itself a finding the caller reports.
type Family ¶
type Family struct {
Name string // report label
Model string // id exactly as GET /v1/models lists it
Chat bool // false = nothing is served on /v1/chat/completions for this id
Tools bool // catalog says supports_tools
}
Family is one row of the compatibility matrix: a model family #138 names, and what the gateway actually serves for it.
type Frame ¶
Frame is one SSE data payload, paired with the event name that preceded it when the producer sent one (Anthropic does, OpenAI does not).
type Reply ¶
Reply is one HTTP exchange. Body carries the whole payload for a JSON answer; Frames carries the SSE payloads in wire order for a stream, including the terminal `data: [DONE]` sentinel so its presence can be asserted.
type Scenario ¶
type Scenario struct {
// Name is the matrix column: openai_* rides /v1/chat/completions, anthropic_*
// rides /v1/messages with the same question behind a different body shape.
Name string
// NeedsChat and NeedsTools gate the cell on what the catalog says the family
// serves, so an unsupported capability reads as "skip" rather than "fail".
NeedsChat bool
NeedsTools bool
Run func(ctx context.Context, c *Client, f Family) (status int, detail string, problems []string)
}
Scenario is one identical request, sent to every family that can take it, on the wire format named in its id. Run returns the HTTP status it saw, a one-line detail for the report, and the contract violations — empty means the cell passes.