Documentation
¶
Overview ¶
Package meridian is the Go SDK for the Meridian engine: a server client for chat and models, an admin client for integrators, and errors you match with errors.As.
Keys spend credit. Use this package only on servers; browsers and mobile apps call your own route, built with the forward sub-package.
Index ¶
- Constants
- func EngineCodes() []string
- func EngineSpecCommit() string
- func EngineTypes() []string
- func WriteError(w http.ResponseWriter, err error)
- type AdminClient
- type AdminModels
- type Analytics
- type AssistantMessage
- type CatalogueModel
- type ChatChoice
- type ChatChunk
- type ChatCompletion
- type ChatMessage
- type ChatParams
- type ChatService
- type ChatStream
- func (s *ChatStream) Chunks() iter.Seq2[ChatChunk, error]
- func (s *ChatStream) Close() error
- func (s *ChatStream) RequestID() string
- func (s *ChatStream) ServeSSE(w http.ResponseWriter, mapError func(*Error) *Error) error
- func (s *ChatStream) Text() (string, error)
- func (s *ChatStream) Usage() *Usage
- type ChunkChoice
- type ChunkDelta
- type Client
- type ContentPart
- type CreateOrganisation
- type CreateProject
- type CredentialMetadata
- type Error
- type ImageURL
- type IssueKey
- type IssuedKey
- type Key
- type Keys
- type LogPage
- type LogRow
- type Logs
- type LogsQuery
- type Model
- type ModelCapabilities
- type ModelPerformance
- type ModelsService
- type Option
- type Organisation
- type Organisations
- func (s *Organisations) Create(ctx context.Context, in CreateOrganisation) (*Organisation, error)
- func (s *Organisations) Get(ctx context.Context, org string) (*Organisation, error)
- func (s *Organisations) GetByReference(ctx context.Context, reference string) (*Organisation, error)
- func (s *Organisations) List(ctx context.Context) ([]Organisation, error)
- type Project
- type ProjectModels
- type Projects
- func (s *Projects) Create(ctx context.Context, org string, in CreateProject) (*Project, error)
- func (s *Projects) Delete(ctx context.Context, org, project string) error
- func (s *Projects) Get(ctx context.Context, org, project string) (*Project, error)
- func (s *Projects) List(ctx context.Context, org string) ([]Project, error)
- func (s *Projects) Update(ctx context.Context, org, project string, in UpdateProject) (*Project, error)
- type ProviderCredentials
- func (s *ProviderCredentials) Delete(ctx context.Context, org, provider string) error
- func (s *ProviderCredentials) List(ctx context.Context, org string) ([]CredentialMetadata, error)
- func (s *ProviderCredentials) Set(ctx context.Context, org, provider string, in SetCredential) (*CredentialMetadata, error)
- type Role
- type SetCredential
- type TimeRange
- type Tool
- type ToolCall
- type ToolCallDelta
- type ToolCallDeltaFunction
- type ToolCallFunction
- type ToolFunction
- type UpdateProject
- type Usage
- type UsageQuery
- type UsageReport
- type UsageSummary
Constants ¶
const ( CodeInvalidRequest = "invalid_request" CodeInvalidAPIKey = "invalid_api_key" CodeKeyRevoked = "key_revoked" CodeKeyExpired = "key_expired" CodeModelNotAllowed = "model_not_allowed" CodeBYOKRequired = "byok_required" CodeProjectHostMismatch = "project_host_mismatch" CodeModelNotFound = "model_not_found" CodeRouteNotFound = "route_not_found" CodeMethodNotAllowed = "method_not_allowed" CodeCapabilityUnsupported = "capability_unsupported" CodeBodyTooLarge = "body_too_large" CodeRateLimited = "rate_limited" CodeInsufficientCredit = "insufficient_credit" CodeHardLimitReached = "hard_limit_reached" CodeEntitlementMissing = "entitlement_missing" CodeIdempotencyConflict = "idempotency_conflict" CodeUpstreamError = "upstream_error" CodeDeadlineExceeded = "deadline_exceeded" CodeInternal = "internal" CodeInvalidToken = "invalid_token" CodePermissionDenied = "permission_denied" CodeNotFound = "not_found" CodeConflict = "conflict" )
Engine error codes: the engine's closed list, in the engine's order.
const ( CodeNetworkError = "network_error" CodeAborted = "aborted" )
SDK-only codes. The SDK adds no others.
const ( TypeInvalidRequest = "invalid_request_error" TypeAuthentication = "authentication_error" TypePermission = "permission_error" TypeRateLimit = "rate_limit_error" TypeAPI = "api_error" TypeClient = "client_error" )
Error types: the engine's five, and client_error for failures inside the SDK.
const Version = "0.1.0"
Version is the SDK version sent in the User-Agent header.
Variables ¶
This section is empty.
Functions ¶
func EngineCodes ¶
func EngineCodes() []string
EngineCodes returns the engine's 28 error codes in the engine's order.
func EngineSpecCommit ¶
func EngineSpecCommit() string
EngineSpecCommit is the engine commit whose OpenAPI documents this SDK's types were checked against. Support asks for it.
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError answers an HTTP request with err as the engine's error envelope: the error's own code, message and request id, with its HTTP status (502 when it has none, as a network or configuration error does, or when the status is not an error status). It hides nothing, and the SDK-only type client_error is written as api_error. An error that is not a *Error is an internal error with no detail (so is a nil *Error, however it is wrapped). A request id that is not printable ASCII (1–255 bytes) is left out of the header and the body. A rate_limited error that came from the engine with a valid Retry-After (seconds or an HTTP date) repeats it.
A route that a browser or an app calls must not show it why your server failed (a missing key, an unreachable engine, your own account's credit): use package forward, which applies the generic 503, or choose what to show yourself.
Types ¶
type AdminClient ¶
type AdminClient struct {
Organisations *Organisations
Projects *Projects
Keys *Keys
ProviderCredentials *ProviderCredentials
ProjectModels *ProjectModels
Models *AdminModels
Analytics *Analytics
Logs *Logs
}
AdminClient provisions Meridian for an integrator with a gmi_ key, on the engine's admin address (a separate listener from the one chat uses). Provisioning belongs on your server: never put a gmi_ key in a browser or an app. It is safe for concurrent use.
It wraps the engine's integrator operations except the supplier-catalogue ones, which return only supplier prices; no SDK exposes a price (D-27, owner decision of 10 October 2026), so billing reads the catalogue from the engine's admin API directly. An organisation is renamed and deleted by a person in the console, not through an integrator key.
The zero value, and a nil service, return an invalid_request error from every call.
func NewAdminClient ¶
func NewAdminClient(baseURL, key string, opts ...Option) *AdminClient
NewAdminClient returns an admin client for the engine's admin address, with an integrator key (gmi_…). It never fails: a bad URL or empty key gives a client whose calls return an invalid_request error and send nothing.
type AdminModels ¶
type AdminModels struct {
// contains filtered or unexported fields
}
AdminModels reads the model catalogue.
func (*AdminModels) Get ¶
func (s *AdminModels) Get(ctx context.Context, model string) (*CatalogueModel, error)
Get returns one catalogue model.
func (*AdminModels) List ¶
func (s *AdminModels) List(ctx context.Context) ([]CatalogueModel, error)
List returns the catalogue's models.
type Analytics ¶
type Analytics struct {
// contains filtered or unexported fields
}
Analytics reads usage.
func (*Analytics) Usage ¶
func (s *Analytics) Usage(ctx context.Context, q UsageQuery) (*UsageReport, error)
Usage returns a project's usage in a window: requests, tokens and latency.
type AssistantMessage ¶
type AssistantMessage struct {
Role string `json:"role"`
Content *string `json:"content"`
Reasoning *string `json:"reasoning,omitempty"`
ReasoningContent *string `json:"reasoning_content,omitempty"`
Refusal *string `json:"refusal,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
AssistantMessage is the model's message.
type CatalogueModel ¶
type CatalogueModel struct {
ID string `json:"id"`
Provider string `json:"provider"`
Capabilities ModelCapabilities `json:"capabilities"`
ContextTokens int64 `json:"context_tokens"`
MaxOutputTokens int64 `json:"max_output_tokens"`
}
CatalogueModel is a model in the catalogue, with what it supports.
type ChatChoice ¶
type ChatChoice struct {
Index int `json:"index"`
Message AssistantMessage `json:"message"`
FinishReason string `json:"finish_reason"`
}
ChatChoice is one choice of a buffered reply.
type ChatChunk ¶
type ChatChunk struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []ChunkChoice `json:"choices"`
Usage *Usage `json:"usage,omitempty"`
}
ChatChunk is one streamed chunk.
type ChatCompletion ¶
type ChatCompletion struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []ChatChoice `json:"choices"`
Usage Usage `json:"usage"`
// RequestID is the engine's request id (the X-Request-Id header), not part of the reply body.
RequestID string `json:"-"`
}
ChatCompletion is a buffered chat reply.
func (*ChatCompletion) Text ¶
func (c *ChatCompletion) Text() string
Text is the first choice's content, or "".
type ChatMessage ¶
type ChatMessage struct {
Role Role `json:"role"`
Content any `json:"content,omitempty"`
Name string `json:"name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
ChatMessage is one message. Content is a string, a []ContentPart, or nil.
type ChatParams ¶
type ChatParams struct {
Messages []ChatMessage `json:"messages,omitempty"`
Model string `json:"model,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
MaxCompletionTokens *int `json:"max_completion_tokens,omitempty"`
N *int `json:"n,omitempty"`
Stop any `json:"stop,omitempty"`
Tools []Tool `json:"tools,omitempty"`
ToolChoice any `json:"tool_choice,omitempty"`
ResponseFormat any `json:"response_format,omitempty"`
User string `json:"user,omitempty"`
// IdempotencyKey is sent on every retry of this call; empty means the SDK generates one. It
// must be 1–255 bytes, each visible ASCII (0x21–0x7E, so no spaces), or the call is refused
// with invalid_request before anything is sent.
IdempotencyKey string `json:"-"`
// Extra holds request fields the engine forwards to the provider. Known fields and the
// stream flags always win over Extra.
Extra map[string]any `json:"-"`
}
ChatParams is a chat request. Leave Model empty to let Meridian choose (D-25).
type ChatService ¶
type ChatService struct {
// contains filtered or unexported fields
}
ChatService sends chat requests. Its zero value, or a nil *ChatService, returns an invalid_request error from every call instead of panicking.
func (*ChatService) Create ¶
func (s *ChatService) Create(ctx context.Context, p ChatParams) (*ChatCompletion, error)
Create sends a chat request and waits for the whole reply. The engine sends headers only after the whole reply is generated, so Create waits up to 300 s for them (Stream and the admin client 60 s); WithHeaderTimeout, if given, replaces that for every call. Bound the call with ctx.
func (*ChatService) Stream ¶
func (s *ChatService) Stream(ctx context.Context, p ChatParams) (*ChatStream, error)
Stream sends a chat request and returns the reply as a stream. Usage is always requested. Cancelling ctx stops the stream, so a handler relaying to a browser should pass r.Context(). Close a stream you do not read.
type ChatStream ¶
type ChatStream struct {
// contains filtered or unexported fields
}
ChatStream is one streamed chat reply. Read it once, with Chunks, Text or ServeSSE. Reading to the end or breaking out of Chunks releases the connection; a stream that is never read must be released with Close.
func (*ChatStream) Chunks ¶
func (s *ChatStream) Chunks() iter.Seq2[ChatChunk, error]
Chunks yields the reply chunk by chunk. A failure arrives as the error of the last iteration. Breaking out of the loop closes the stream and cancels the upstream request.
func (*ChatStream) Close ¶
func (s *ChatStream) Close() error
Close stops the stream and cancels the upstream request. It is safe to call more than once, and does nothing on a stream that was not returned by Chat.Stream (a zero or nil *ChatStream).
func (*ChatStream) RequestID ¶
func (s *ChatStream) RequestID() string
RequestID is the engine's request id for this stream; empty when the engine sent none, or one that is not printable ASCII (1–255 bytes).
func (*ChatStream) ServeSSE ¶
func (s *ChatStream) ServeSSE(w http.ResponseWriter, mapError func(*Error) *Error) error
ServeSSE relays the stream to w byte for byte, flushing after each event, and returns the real error that ended it (nil after [DONE]). Use it from your own route handler.
mapError, if not nil, sees every error that ends the stream: an engine error frame, a malformed frame, a dropped connection or a cancellation. It receives a copy; any non-nil *Error it returns (a new one, or the copy edited in place) is relayed as a final error frame instead of the original, and the frame that carried the original error is never written. Returning nil leaves an engine error frame as it came. With a nil mapError engine error frames are relayed as they came, and an SDK-side failure writes nothing more (the stream just stops).
Pass the incoming request's context (r.Context()) to Chat.Stream so a browser disconnect cancels the upstream request.
func (*ChatStream) Text ¶
func (s *ChatStream) Text() (string, error)
Text collects the whole reply. On failure it returns the text so far and the error.
func (*ChatStream) Usage ¶
func (s *ChatStream) Usage() *Usage
Usage is the token counts reported at the end of the stream, or nil before then.
type ChunkChoice ¶
type ChunkChoice struct {
Index int `json:"index"`
Delta ChunkDelta `json:"delta"`
FinishReason *string `json:"finish_reason"`
}
ChunkChoice is one choice of a chunk.
type ChunkDelta ¶
type ChunkDelta struct {
Role *string `json:"role,omitempty"`
Content *string `json:"content,omitempty"`
Reasoning *string `json:"reasoning,omitempty"`
ReasoningContent *string `json:"reasoning_content,omitempty"`
Refusal *string `json:"refusal,omitempty"`
ToolCalls []ToolCallDelta `json:"tool_calls,omitempty"`
}
ChunkDelta is what a chunk adds.
type Client ¶
type Client struct {
Chat *ChatService
Models *ModelsService
}
Client is the server client for chat and models. It is safe for concurrent use.
type ContentPart ¶
type ContentPart struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ImageURL *ImageURL `json:"image_url,omitempty"`
}
ContentPart is one part of a multi-part message.
func ImagePart ¶
func ImagePart(url string) ContentPart
ImagePart is an image content part (an https or data URL).
type CreateOrganisation ¶
type CreateOrganisation struct {
Name string `json:"name"`
Slug *string `json:"slug,omitempty"`
ExternalReference *string `json:"external_reference,omitempty"`
}
CreateOrganisation creates an organisation. With an ExternalReference a repeated create returns the existing organisation, so the SDK can safely retry it.
type CreateProject ¶
type CreateProject struct {
Name string `json:"name"`
}
CreateProject creates a project.
type CredentialMetadata ¶
type CredentialMetadata struct {
Provider string `json:"provider"`
Hint string `json:"hint"`
CreatedAt string `json:"created_at"`
LastUsedAt *string `json:"last_used_at"`
Policy string `json:"policy"` // "prefer" or "require"
}
CredentialMetadata describes a stored provider key without revealing it.
type Error ¶
type Error struct {
// Code is one of the engine's 28 codes, or CodeNetworkError or CodeAborted.
Code string
// Type is one of the engine's five types, or TypeClient for failures inside the SDK.
Type string
// Status is the HTTP status of the engine's reply. It is 0 when no HTTP reply arrived, and for
// an SDK-side failure inside a stream that had begun (a truncation, an unreadable frame);
// engine error frames carry the status for their code. A malformed or unreadable reply keeps
// its real status.
Status int
// Message is the engine's message, or the SDK's own explanation.
Message string
// Retryable reports whether the same call could succeed if tried again.
Retryable bool
// RequestID is the engine's request id, when known. Give it to Gaussian support.
RequestID string
// EngineCode is the engine's own code when this SDK does not recognise it (a newer engine);
// Code is then CodeInternal. Empty otherwise.
EngineCode string
// contains filtered or unexported fields
}
Error is the only error type the SDK returns. Find it with errors.As.
type IssueKey ¶
type IssueKey struct {
Name *string `json:"name,omitempty"`
RateLimitPerMinute *int64 `json:"rate_limit_per_minute,omitempty"`
RateLimitPerDay *int64 `json:"rate_limit_per_day,omitempty"`
ExpiresInDays *int64 `json:"expires_in_days,omitempty"`
}
IssueKey issues a project key. Every field is optional.
type IssuedKey ¶
type IssuedKey struct {
KeyID string `json:"key_id"`
APIKey string `json:"api_key"`
KeyPrefix string `json:"key_prefix"`
Message string `json:"message"`
}
IssuedKey is a new key. APIKey is the secret: the engine shows it once, so store it now.
It is redacted under every fmt verb (%v, %+v, %#v, %s, %q, %x, %d and the rest) and as a direct log/slog attribute (slog.Any("key", issued)). It is NOT redacted by encoding/json, on purpose: handing a new key back to its owner is the point of Keys.Issue, so json.NewEncoder(w).Encode(issued) carries APIKey. A struct, slice or map that holds an IssuedKey is marshalled by encoding/json too, so slog's JSON handler logs the secret from one: do not log a struct that holds an IssuedKey with a JSON handler; log KeyID and KeyPrefix. (fmt prints a misused operand raw, without calling any method: a value given to %p and a non-error given to %w. go vet reports both.)
func (IssuedKey) Format ¶
Format prints the redacted form under every fmt verb, so no verb reaches the secret.
type Key ¶
type Key struct {
ID string `json:"id"`
ProjectID string `json:"project_id"`
KeyPrefix string `json:"key_prefix"`
Name *string `json:"name"`
RateLimitPerMinute *int64 `json:"rate_limit_per_minute"`
RateLimitPerDay *int64 `json:"rate_limit_per_day"`
CreatedAt string `json:"created_at"`
ExpiresAt *string `json:"expires_at"`
LastUsedAt *string `json:"last_used_at"`
Active bool `json:"active"`
}
Key is a project key's metadata. The secret is never listed.
type Keys ¶
type Keys struct {
// contains filtered or unexported fields
}
Keys manages a project's keys.
func (*Keys) Issue ¶
Issue issues a key and returns its secret once: store IssuedKey.APIKey now. It is retried only when the engine rate-limits it, so a dropped connection never makes a second key.
type LogPage ¶
type LogPage struct {
Logs []LogRow `json:"logs"`
HasMore bool `json:"has_more"`
NextCursor *string `json:"next_cursor"`
}
LogPage is one page of the request log. Pass NextCursor back as LogsQuery.Cursor while HasMore.
type LogRow ¶
type LogRow struct {
ID string `json:"id"`
Model *string `json:"model"`
Provider *string `json:"provider"`
TokensIn *int64 `json:"tokens_in"`
TokensOut *int64 `json:"tokens_out"`
LatencyMs int64 `json:"latency_ms"`
CreatedAt string `json:"created_at"`
Status string `json:"status"`
}
LogRow is one request in the log: tokens and latency, never a cost.
type Logs ¶
type Logs struct {
// contains filtered or unexported fields
}
Logs reads the request log.
type LogsQuery ¶
LogsQuery pages through a project's request log. ProjectID is required; PageSize 0 leaves the size to the engine, and Cursor is a previous page's NextCursor.
type Model ¶
type Model struct {
ID string `json:"id"`
Object string `json:"object"`
OwnedBy string `json:"owned_by"`
}
Model is a model the key may use.
type ModelCapabilities ¶
type ModelCapabilities struct {
Streaming bool `json:"streaming"`
Tools bool `json:"tools"`
Vision bool `json:"vision"`
JSONOutput bool `json:"json_output"`
}
ModelCapabilities is what a catalogue model supports.
type ModelPerformance ¶
type ModelPerformance struct {
Model string `json:"model"`
Requests int64 `json:"requests"`
Tokens *int64 `json:"tokens"`
}
ModelPerformance is one model's share of the usage.
type ModelsService ¶
type ModelsService struct {
// contains filtered or unexported fields
}
ModelsService lists models. Like ChatService, its zero value or nil pointer returns an invalid_request error instead of panicking.
type Option ¶
type Option func(*config)
Option configures a client.
func WithHTTPClient ¶
WithHTTPClient sets the *http.Client used for every request (proxies, TLS, tracing, tests). A nil client is ignored.
func WithHeaderTimeout ¶
WithHeaderTimeout bounds each attempt's wait for response headers, for every call. Without it the wait is 60 s, except for Chat.Create, which waits 300 s because the engine sends headers only after the whole reply is generated. A value that is not positive is ignored. The whole call is bounded only by the context.
func WithMaxRetries ¶
WithMaxRetries sets how many times a retryable failure is retried before the body is read. Values are clamped to 0–10. The default is 2.
func WithUserAgentSuffix ¶
WithUserAgentSuffix appends s to the User-Agent header. A suffix with a byte outside 0x20–0x7E (a newline, a tab, a non-ASCII character) cannot be sent intact: the client is then refused, like one with a bad key, and every call returns invalid_request without sending anything.
type Organisation ¶
type Organisation struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Status string `json:"status"` // "active", "suspended" or "locked"
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
MemberCount int64 `json:"member_count"`
ProjectCount int64 `json:"project_count"`
}
Organisation is a Meridian organisation.
type Organisations ¶
type Organisations struct {
// contains filtered or unexported fields
}
Organisations manages organisations.
func (*Organisations) Create ¶
func (s *Organisations) Create(ctx context.Context, in CreateOrganisation) (*Organisation, error)
Create creates an organisation. With an ExternalReference a repeat returns the existing one, so only then is the call retried after a failure that might have reached the engine.
func (*Organisations) Get ¶
func (s *Organisations) Get(ctx context.Context, org string) (*Organisation, error)
Get returns an organisation by id.
func (*Organisations) GetByReference ¶
func (s *Organisations) GetByReference(ctx context.Context, reference string) (*Organisation, error)
GetByReference returns the organisation you created with this external reference.
func (*Organisations) List ¶
func (s *Organisations) List(ctx context.Context) ([]Organisation, error)
List returns the organisations this integrator created.
type Project ¶
type Project struct {
ID string `json:"id"`
Ref string `json:"ref"`
Name string `json:"name"`
OrgID string `json:"org_id"`
Status string `json:"status"`
DefaultModel *string `json:"default_model"`
CreatedAt string `json:"created_at"`
}
Project is a project in an organisation.
type ProjectModels ¶
type ProjectModels struct {
// contains filtered or unexported fields
}
ProjectModels manages the models a project may use.
type Projects ¶
type Projects struct {
// contains filtered or unexported fields
}
Projects manages an organisation's projects.
func (*Projects) Create ¶
Create creates a project. It is retried only when the engine rate-limits it.
type ProviderCredentials ¶
type ProviderCredentials struct {
// contains filtered or unexported fields
}
ProviderCredentials manages an organisation's own provider keys (BYOK).
func (*ProviderCredentials) Delete ¶
func (s *ProviderCredentials) Delete(ctx context.Context, org, provider string) error
Delete removes the organisation's key for a provider.
func (*ProviderCredentials) List ¶
func (s *ProviderCredentials) List(ctx context.Context, org string) ([]CredentialMetadata, error)
List returns the stored provider keys' metadata, never the keys.
func (*ProviderCredentials) Set ¶
func (s *ProviderCredentials) Set(ctx context.Context, org, provider string, in SetCredential) (*CredentialMetadata, error)
Set stores or replaces the organisation's key for a provider, such as "gemini".
type Role ¶
type Role string
Role is a message role. The engine forwards any role as sent; these are the ones providers accept.
type SetCredential ¶
type SetCredential struct {
Credential string `json:"credential"`
Policy *string `json:"policy,omitempty"`
}
SetCredential stores an organisation's own provider key (BYOK). Policy is "prefer" or "require"; leave it nil for the engine's default.
Like IssuedKey it is redacted under every fmt verb and as a direct log/slog attribute, and NOT redacted by encoding/json (the request body needs the credential). Do not log a struct that holds a SetCredential with slog's JSON handler.
func (SetCredential) Format ¶
func (c SetCredential) Format(f fmt.State, _ rune)
Format prints the redacted form under every fmt verb, so no verb reaches the credential.
func (SetCredential) LogValue ¶
func (c SetCredential) LogValue() slog.Value
LogValue redacts the credential for log/slog.
type Tool ¶
type Tool struct {
Type string `json:"type"`
Function ToolFunction `json:"function"`
}
Tool is a function the model may call.
func FunctionTool ¶
FunctionTool is a function tool.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function ToolCallFunction `json:"function"`
}
ToolCall is a call the model made.
type ToolCallDelta ¶
type ToolCallDelta struct {
Index int `json:"index"`
ID *string `json:"id,omitempty"`
Type *string `json:"type,omitempty"`
Function *ToolCallDeltaFunction `json:"function,omitempty"`
}
ToolCallDelta is part of a streamed tool call.
type ToolCallDeltaFunction ¶
type ToolCallDeltaFunction struct {
Name *string `json:"name,omitempty"`
Arguments *string `json:"arguments,omitempty"`
}
ToolCallDeltaFunction is part of a streamed function call.
type ToolCallFunction ¶
ToolCallFunction is the called function and its JSON arguments.
type ToolFunction ¶
type ToolFunction struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters any `json:"parameters,omitempty"`
}
ToolFunction describes a callable function. Parameters is a JSON Schema object.
type UpdateProject ¶
type UpdateProject struct {
Name *string `json:"name,omitempty"`
Status *string `json:"status,omitempty"`
DefaultModel *string `json:"default_model,omitempty"`
ClearDefaultModel bool `json:"-"`
}
UpdateProject changes exactly one of Name, Status ("active" or "suspended") or DefaultModel. Set ClearDefaultModel to clear the default model (the engine reads JSON null as "clear"); setting it together with DefaultModel is refused as an invalid_request.
func (UpdateProject) MarshalJSON ¶
func (u UpdateProject) MarshalJSON() ([]byte, error)
MarshalJSON sends "default_model": null when ClearDefaultModel is set.
type Usage ¶
type Usage struct {
PromptTokens *int `json:"prompt_tokens,omitempty"`
CompletionTokens *int `json:"completion_tokens,omitempty"`
TotalTokens *int `json:"total_tokens,omitempty"`
}
Usage is the reply's token counts. A count the engine did not report is nil, never 0. There is never a price or cost (D-27).
type UsageQuery ¶
type UsageQuery struct {
ProjectID, From, To string
}
UsageQuery selects a usage window. ProjectID is required; From and To are RFC 3339 times and optional.
type UsageReport ¶
type UsageReport struct {
Summary UsageSummary `json:"summary"`
ModelPerformance []ModelPerformance `json:"model_performance"`
TimeRange TimeRange `json:"time_range"`
}
UsageReport is a project's usage in a window: requests, tokens and latency, never cost.
type UsageSummary ¶
type UsageSummary struct {
TotalRequests int64 `json:"total_requests"`
SuccessfulRequests int64 `json:"successful_requests"`
TotalTokens *int64 `json:"total_tokens"`
AverageLatencyMs int64 `json:"average_latency_ms"`
P95LatencyMs int64 `json:"p95_latency_ms"`
P99LatencyMs int64 `json:"p99_latency_ms"`
PercentileSampleCount int64 `json:"percentile_sample_count"`
PercentilesSampled bool `json:"percentiles_sampled"`
SuccessRate float64 `json:"success_rate"`
ErrorRate float64 `json:"error_rate"`
}
UsageSummary totals a usage window. TotalTokens is nil when any request's token count is unknown.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package forward is a ready http.Handler that forwards a browser's or mobile app's chat to Meridian with your server's key.
|
Package forward is a ready http.Handler that forwards a browser's or mobile app's chat to Meridian with your server's key. |
|
internal
|
|
|
cmd/contract
command
Command contract runs the contract suite against the real local engine, in simulator mode only.
|
Command contract runs the contract suite against the real local engine, in simulator mode only. |
|
cmd/downconvert
command
Command downconvert rewrites an OpenAPI 3.1 document into the OpenAPI 3.0 subset that oapi-codegen turns into plain standard-library Go.
|
Command downconvert rewrites an OpenAPI 3.1 document into the OpenAPI 3.0 subset that oapi-codegen turns into plain standard-library Go. |
|
cmd/pinspec
command
Command pinspec copies the engine's committed OpenAPI documents into spec/ and records the engine commit in spec/SOURCE.json.
|
Command pinspec copies the engine's committed OpenAPI documents into spec/ and records the engine commit in spec/SOURCE.json. |
|
contract
Package contract holds the contract suite: the SDK against the real local engine in simulator mode.
|
Package contract holds the contract suite: the SDK against the real local engine in simulator mode. |
|
contractguard
Package contractguard is the contract guard: a contract run talks to the real local engine and must never spend money, so it may start only when the engine is proven to be the provider simulator, started from this runtime's env file, with no paid key anywhere it could read one.
|
Package contractguard is the contract guard: a contract run talks to the real local engine and must never spend money, so it may start only when the engine is proven to be the provider simulator, started from this runtime's env file, with no paid key anywhere it could read one. |
|
fakeengine
Package fakeengine is an in-memory Meridian engine for the SDK's tests.
|
Package fakeengine is an in-memory Meridian engine for the SDK's tests. |
|
gen/admin
Package admin provides primitives to interact with the openapi HTTP API.
|
Package admin provides primitives to interact with the openapi HTTP API. |
|
gen/public
Package public holds types generated by oapi-codegen from the pinned public engine document.
|
Package public holds types generated by oapi-codegen from the pinned public engine document. |
|
idemkey
Package idemkey holds the one rule for a valid Idempotency-Key, shared by the root package (a caller's ChatParams.IdempotencyKey) and package forward (a browser's header), so the two cannot drift apart.
|
Package idemkey holds the one rule for a valid Idempotency-Key, shared by the root package (a caller's ChatParams.IdempotencyKey) and package forward (a browser's header), so the two cannot drift apart. |