XU XUv0.16.0

#github.com/xulang-org/packages/gateway

import: gateway #github.com/xulang-org/packages/gateway

counts: 4 functions, 27 methods, 5 types, 0 constants, 0 method sets

External package `gateway #github.com/xulang-org/packages/gateway`, provided by github.com/xulang-org/packages.

github.com/xulang-org/packages · 1.17.2 · Install and use

struct ProviderPassthrough

XuAPI
pub struct ProviderPassthrough {
    pub anthropic_cache_system bool
    pub anthropic_cache_control string
    pub anthropic_thinking_budget int
    pub anthropic_extra_body_json string
    pub gemini_safety_settings_json string
    pub gemini_thinking_budget int
    pub gemini_extra_body_json string
    pub openai_extra_body_json string
}

Purpose

Structure encapsulating anthropic_cache_system, anthropic_cache_control, anthropic_thinking_budget, anthropic_extra_body_json, gemini_safety_settings_json.

Public fields

anthropic_cache_system bool
field (bool)
anthropic_cache_control string
field (string)
anthropic_thinking_budget int
field (int)
anthropic_extra_body_json string
field (string)
gemini_safety_settings_json string
field (string)
gemini_thinking_budget int
field (int)
gemini_extra_body_json string
field (string)
openai_extra_body_json string
field (string)

empty_passthrough

XuAPI
pub fn empty_passthrough() ProviderPassthrough

Purpose

Empty passthrough.

Parameters

No arguments are required.

Returns

ProviderPassthrough — a value of this type

struct ProviderRoute

XuAPI
pub struct ProviderRoute {
    pub name string
    pub provider string
    pub client openai.Client
    pub model string
    pub input_cost_per_1m f64
    pub output_cost_per_1m f64
    pub enabled bool
    pub weight int
    pub consecutive_failures int
    pub circuit_open_until_ms int
    pub passthrough ProviderPassthrough
}

Purpose

Structure encapsulating name, provider, client, model, input_cost_per_1m.

Public fields

name string
name
provider string
field (string)
client openai.Client
field (openai.Client)
model string
field (string)
input_cost_per_1m f64
field (f64)
output_cost_per_1m f64
field (f64)
enabled bool
field (bool)
weight int
field (int)
consecutive_failures int
field (int)
circuit_open_until_ms int
field (int)
passthrough ProviderPassthrough
field (ProviderPassthrough)

struct SemanticCacheEntry

XuAPI
pub struct SemanticCacheEntry {
    pub key_text string
    pub embedding []f32
    pub response_content string
    pub model string
}

Purpose

Structure encapsulating key_text, embedding, response_content, model.

Public fields

key_text string
field (string)
embedding []f32
field ([]f32)
response_content string
field (string)
model string
field (string)

struct GatewayStats

XuAPI
pub struct GatewayStats {
    pub total_requests int
    pub cache_hits int
    pub fallbacks int
    pub failed_requests int
    pub total_prompt_tokens int
    pub total_completion_tokens int
    pub estimated_cost_usd f64
}

Purpose

Structure encapsulating total_requests, cache_hits, fallbacks, failed_requests, total_prompt_tokens.

Public fields

total_requests int
field (int)
cache_hits int
field (int)
fallbacks int
field (int)
failed_requests int
field (int)
total_prompt_tokens int
field (int)
total_completion_tokens int
field (int)
estimated_cost_usd f64
field (f64)

struct Gateway

XuAPI
pub struct Gateway {

}

Purpose

Gateway context or state structure.

Public fields

This type has no public fields.

new_gateway

XuAPI
pub fn new_gateway() Gateway

Purpose

Construct gateway.

Parameters

No arguments are required.

Returns

Gateway — a value of this type

($&Gateway) set_redis_pool

XuAPI
pub fn (g $&Gateway) set_redis_pool(pool redis.Pool, prefix string)

Purpose

Operation on $&Gateway: set redis pool.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
pool redis.Pool
pool (redis.Pool)
prefix string
prefix (string)

Returns

This call does not return a value.

($&Gateway) set_redis_store

XuAPI
pub fn (g $&Gateway) set_redis_store(addr string, prefix string)

Purpose

Operation on $&Gateway: set redis store.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
addr string
address (string)
prefix string
prefix (string)

Returns

This call does not return a value.

($&Gateway) set_redis_store_auth

XuAPI
pub fn (g $&Gateway) set_redis_store_auth(addr string, password string, prefix string)

Purpose

Operation on $&Gateway: set redis store auth.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
addr string
address (string)
password string
password (string)
prefix string
prefix (string)

Returns

This call does not return a value.

($&Gateway) set_redis_url

XuAPI
pub fn (g $&Gateway) set_redis_url(raw_url string, prefix string)

Purpose

Operation on $&Gateway: set redis url.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
raw_url string
raw_url (string)
prefix string
prefix (string)

Returns

This call does not return a value.

($&Gateway) set_cache_ttl

XuAPI
pub fn (g $&Gateway) set_cache_ttl(seconds int)

Purpose

Operation on $&Gateway: set cache ttl.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
seconds int
seconds (int)

Returns

This call does not return a value.

(&Gateway) is_redis_enabled

XuAPI
pub fn (g &Gateway) is_redis_enabled() bool

Purpose

Operation on &Gateway: whether it is redis enabled.

Parameters

g &Gateway
The Gateway instance used by this call (borrow).

Returns

bool — true or false

($&Gateway) close_redis

XuAPI
pub fn (g $&Gateway) close_redis()

Purpose

Operation on $&Gateway: close redis.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Gateway) add_route

XuAPI
pub fn (g $&Gateway) add_route(name string, client openai.Client, model string, input_cost_per_1m f64, output_cost_per_1m f64)

Purpose

Operation on $&Gateway: add route.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
name string
name (string)
client openai.Client
client (openai.Client)
model string
model (string)
input_cost_per_1m f64
input_cost_per_1m (f64)
output_cost_per_1m f64
output_cost_per_1m (f64)

Returns

This call does not return a value.

($&Gateway) add_weighted_route

XuAPI
pub fn (g $&Gateway) add_weighted_route(name string, client openai.Client, model string, input_cost_per_1m f64, output_cost_per_1m f64, weight int)

Purpose

Operation on $&Gateway: add weighted route.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
name string
name (string)
client openai.Client
client (openai.Client)
model string
model (string)
input_cost_per_1m f64
input_cost_per_1m (f64)
output_cost_per_1m f64
output_cost_per_1m (f64)
weight int
weight (int)

Returns

This call does not return a value.

($&Gateway) add_anthropic_route

XuAPI
pub fn (g $&Gateway) add_anthropic_route(name string, client anthropic.Client, model string, input_cost_per_1m f64, output_cost_per_1m f64, weight int)

Purpose

Operation on $&Gateway: add anthropic route.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
name string
name (string)
client anthropic.Client
client (anthropic.Client)
model string
model (string)
input_cost_per_1m f64
input_cost_per_1m (f64)
output_cost_per_1m f64
output_cost_per_1m (f64)
weight int
weight (int)

Returns

This call does not return a value.

($&Gateway) add_gemini_route

XuAPI
pub fn (g $&Gateway) add_gemini_route(name string, client gemini.Client, model string, input_cost_per_1m f64, output_cost_per_1m f64, weight int)

Purpose

Operation on $&Gateway: add gemini route.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
name string
name (string)
client gemini.Client
client (gemini.Client)
model string
model (string)
input_cost_per_1m f64
input_cost_per_1m (f64)
output_cost_per_1m f64
output_cost_per_1m (f64)
weight int
weight (int)

Returns

This call does not return a value.

($&Gateway) set_route_passthrough

XuAPI
pub fn (g $&Gateway) set_route_passthrough(name string, pt ProviderPassthrough) bool

Purpose

Operation on $&Gateway: set route passthrough.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
name string
name (string)
pt ProviderPassthrough
pt (ProviderPassthrough)

Returns

bool — true or false

($&Gateway) set_circuit_breaker

XuAPI
pub fn (g $&Gateway) set_circuit_breaker(fail_threshold int, cooldown_ms int)

Purpose

Operation on $&Gateway: set circuit breaker.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
fail_threshold int
fail_threshold (int)
cooldown_ms int
cooldown_ms (int)

Returns

This call does not return a value.

($&Gateway) reset_circuits

XuAPI
pub fn (g $&Gateway) reset_circuits()

Purpose

Operation on $&Gateway: reset circuits.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Gateway) set_rate_limit

XuAPI
pub fn (g $&Gateway) set_rate_limit(requests_per_min int)

Purpose

Operation on $&Gateway: set rate limit.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
requests_per_min int
requests_per_min (int)

Returns

This call does not return a value.

($&Gateway) enable_semantic_cache

XuAPI
pub fn (g $&Gateway) enable_semantic_cache(threshold f64, max_entries int)

Purpose

Operation on $&Gateway: enable semantic cache.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
threshold f64
threshold (f64)
max_entries int
max_entries (int)

Returns

This call does not return a value.

(&Gateway) estimate_cost_usd

XuAPI
pub fn (g &Gateway) estimate_cost_usd(route_idx int, prompt_tokens int, completion_tokens int) f64

Purpose

Operation on &Gateway: estimate cost usd.

Parameters

g &Gateway
The Gateway instance used by this call (borrow).
route_idx int
route_idx (int)
prompt_tokens int
prompt_tokens (int)
completion_tokens int
completion_tokens (int)

Returns

f64 — a value of this type

openai_req_to_anthropic_with

XuAPI
pub fn openai_req_to_anthropic_with(req &openai.ChatRequest, model string, pt &ProviderPassthrough) anthropic.MessagesRequest

Purpose

Openai req to anthropic with.

Parameters

req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)
model string
model (string)
pt &ProviderPassthrough
pt (read-only borrow; caller keeps the original; type &ProviderPassthrough)

Returns

anthropic.MessagesRequest — a value of this type

openai_req_to_gemini_with

XuAPI
pub fn openai_req_to_gemini_with(req &openai.ChatRequest, model string, pt &ProviderPassthrough) gemini.GenerateRequest

Purpose

Openai req to gemini with.

Parameters

req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)
model string
model (string)
pt &ProviderPassthrough
pt (read-only borrow; caller keeps the original; type &ProviderPassthrough)

Returns

gemini.GenerateRequest — a value of this type

($&Gateway) chat_with_passthrough

XuAPI
pub fn (g $&Gateway) chat_with_passthrough(req &openai.ChatRequest, pt &ProviderPassthrough) openai.ChatResponse

Purpose

Operation on $&Gateway: chat with passthrough. Throws on failure; handle the error or propagate it to the caller.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)
pt &ProviderPassthrough
pt (read-only borrow; caller keeps the original; type &ProviderPassthrough)

Returns

openai.ChatResponse — a value of this type

($&Gateway) chat_with_fallback

XuAPI
pub fn (g $&Gateway) chat_with_fallback(req &openai.ChatRequest) openai.ChatResponse

Purpose

Operation on $&Gateway: chat with fallback. Throws on failure; handle the error or propagate it to the caller.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)

Returns

openai.ChatResponse — a value of this type

($&Gateway) chat_weighted

XuAPI
pub fn (g $&Gateway) chat_weighted(req &openai.ChatRequest) openai.ChatResponse

Purpose

Operation on $&Gateway: chat weighted. Throws on failure; handle the error or propagate it to the caller.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)

Returns

openai.ChatResponse — a value of this type

($&Gateway) chat_stream_with_fallback

XuAPI
pub fn (g $&Gateway) chat_stream_with_fallback(req &openai.ChatRequest, on_delta fn(openai.StreamDelta) bool) openai.ChatResponse

Purpose

Operation on $&Gateway: chat stream with fallback. Throws on failure; handle the error or propagate it to the caller.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)
on_delta fn(openai.StreamDelta) bool
on_delta (function value; type fn(openai.StreamDelta) bool)

Returns

openai.ChatResponse — a value of this type

($&Gateway) chat_stream_chan_with_fallback

XuAPI
pub fn (g $&Gateway) chat_stream_chan_with_fallback(req &openai.ChatRequest, ch chan openai.StreamDelta) openai.ChatResponse

Purpose

Operation on $&Gateway: chat stream chan with fallback. Throws on failure; handle the error or propagate it to the caller.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)
ch chan openai.StreamDelta
character code (channel; type chan openai.StreamDelta)

Returns

openai.ChatResponse — a value of this type

($&Gateway) chat_stream_weighted

XuAPI
pub fn (g $&Gateway) chat_stream_weighted(req &openai.ChatRequest, on_delta fn(openai.StreamDelta) bool) openai.ChatResponse

Purpose

Operation on $&Gateway: chat stream weighted. Throws on failure; handle the error or propagate it to the caller.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)
on_delta fn(openai.StreamDelta) bool
on_delta (function value; type fn(openai.StreamDelta) bool)

Returns

openai.ChatResponse — a value of this type

($&Gateway) chat_stream_chan_weighted

XuAPI
pub fn (g $&Gateway) chat_stream_chan_weighted(req &openai.ChatRequest, ch chan openai.StreamDelta) openai.ChatResponse

Purpose

Operation on $&Gateway: chat stream chan weighted. Throws on failure; handle the error or propagate it to the caller.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)
ch chan openai.StreamDelta
character code (channel; type chan openai.StreamDelta)

Returns

openai.ChatResponse — a value of this type

($&Gateway) chat_cached

XuAPI
pub fn (g $&Gateway) chat_cached(req &openai.ChatRequest, query_emb &[]f32) openai.ChatResponse

Purpose

Operation on $&Gateway: chat cached. Throws on failure; handle the error or propagate it to the caller.

Parameters

g $&Gateway
The Gateway instance used by this call (exclusive borrow).
req &openai.ChatRequest
req (read-only borrow; caller keeps the original; type &openai.ChatRequest)
query_emb &[]f32
query_emb (read-only borrow; caller keeps the original; type &[]f32)

Returns

openai.ChatResponse — a value of this type

(&Gateway) get_stats

XuAPI
pub fn (g &Gateway) get_stats() GatewayStats

Purpose

Operation on &Gateway: read stats.

Parameters

g &Gateway
The Gateway instance used by this call (borrow).

Returns

GatewayStats — a value of this type

(&Gateway) format_metrics_prometheus

XuAPI
pub fn (g &Gateway) format_metrics_prometheus() string

Purpose

Operation on &Gateway: format as metrics prometheus.

Parameters

g &Gateway
The Gateway instance used by this call (borrow).

Returns

string — result string