gaise-api 4.0.0

Axum HTTP server for GAISe — exposes /v1/instruct, /v1/instruct/stream, and /v1/embeddings
Documentation

gaise-api

crates.io docs.rs License: MIT OR Apache-2.0

Axum HTTP server for GAISe — exposes all GenAI providers behind a unified REST API with SSE streaming.

Endpoints

Method Path Description
POST /v1/decision Typed decisions with typesafe::jev (/v1/systemone is a deprecated alias)
POST /v1/instruct Non-streaming instruct request
POST /v1/instruct/stream Server-Sent Events streaming
POST /v1/embeddings Generate embedding vectors
GET /v1/models List models across configured providers (?provider=, ?operation=, ?include_details=, ?include_raw=)
GET /v1/models/{provider}::{id} One model record
GET /v1/live WebSocket for real-time audio/text sessions (feature = live)

Quick Start

# Set provider keys
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GEMINI_API_KEY="AIza..."

# Run the server
cargo run -p gaise-api
# Listening on 0.0.0.0:3000
# Call any provider via the same endpoint
curl -X POST http://localhost:3000/v1/instruct \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai::gpt-5.6-terra",
    "input": {
      "role": "user",
      "content": {"type": "text", "text": "Hello!"}
    }
  }'

Change "model" to "anthropic::claude-sonnet-5" or "gemini::gemini-3.8-flash" — same endpoint, same format.

Live / Realtime (feature = "live")

Enable with cargo run -p gaise-api --features live. The /v1/live endpoint upgrades to a WebSocket for bidirectional audio + text streaming.

Protocol:

  1. Client sends a JSON GaiseLiveConfig as the first message (model, voice, modalities, tools, etc.)
  2. Server connects to the provider and begins forwarding:
    • Client -> Server: JSON text frames (GaiseLiveInput) or binary frames (raw PCM16 audio at 16kHz)
    • Server -> Client: JSON text frames (GaiseLiveEvent) or binary frames (PCM audio with 4-byte LE sample rate header)

Environment Variables

Variable Description
GAISE_PORT Server port (default: 3000)
OLLAMA_URL Ollama API URL
OPENAI_API_URL / OPENAI_API_KEY OpenAI credentials
ANTHROPIC_API_URL / ANTHROPIC_API_KEY Anthropic credentials
GEMINI_API_URL / GEMINI_API_KEY Gemini credentials
VERTEXAI_API_URL / VERTEXAI_SA_PATH Vertex AI credentials
BEDROCK_REGION AWS Bedrock region
TYPESAFE_API_KEY TypeSafe API key
TYPESAFE_API_URL / TYPESAFE_BASE_URL TypeSafe API root without /v1; defaults to https://api.typesafe.ai

As a Library

use std::sync::Arc;
use gaise_api::{create_app, AppState};
use gaise_client::{GaiseClientService, GaiseClientConfig};

let config = GaiseClientConfig { /* ... */ ..Default::default() };
let state = Arc::new(AppState {
    client_service: GaiseClientService::new(config),
});

let app = create_app(state);
// Mount into your own Axum server

Part of GAISe

License: MIT OR Apache-2.0, at your option (see LICENSE-APACHE and LICENSE-MIT). Versions 0.2.2 and earlier remain AGPL-3.0-only on crates.io.

Decision and TypeSafe Jev

The Decision operation evaluates questions about shared context and returns typed decisions. Use it for tasks such as ticket routing, urgency detection, eligibility checks, and rubric scoring. GAISe currently provides this operation through TypeSafe AI's Jev model, selected as typesafe::jev.

The router removes typesafe::; the adapter maps jev to TypeSafe's jev-latest and sends POST https://api.typesafe.ai/v1/systemone. The response keeps the provider-reported model ID so you can record which version answered. Model listing maps the upstream jev-latest alias back to typesafe::jev.

Each request contains a shared state and a map of named questions. Answers use those same names. Questions are evaluated independently against the state; use application code to combine their results or to decide when a threshold is met.

Question type Criteria Answer
noul Optional true / false descriptions noul: probability from 0 to 1; GAISe does not convert it to a Boolean
choice Object mapping option names to descriptions (or null) Selected choice, probability per option, and confidence
score Ordered array with at least two level descriptions Fractional expected score, probability per level, legend, and confidence

Scores use zero-based rubric positions. For example, a three-level rubric has positions 0, 1, and 2; a returned score of 1.2 falls between the middle and highest levels. Confidence is a provider-reported measure derived from the distribution; GAISe preserves it without recalculating it or treating it as a correctness guarantee.

HTTP: POST /v1/decision

Configure the GAISe server with TYPESAFE_API_KEY, then run cargo run -p gaise-api from the repository. Save this request as request.json:

{
  "model": "typesafe::jev",
  "state": {
    "ticket": "I was charged twice. Please fix this today."
  },
  "questions": {
    "urgent": {
      "type": "noul",
      "instructions": "Does this ticket need urgent attention?"
    },
    "team": {
      "type": "choice",
      "instructions": "Which team should handle this ticket?",
      "criteria": {
        "billing": "Payments, invoices, or refunds",
        "technical": "Bugs or integration problems"
      }
    },
    "severity": {
      "type": "score",
      "instructions": "How severe is the customer impact?",
      "criteria": [
        "Low: minor inconvenience",
        "Medium: a problem needing attention",
        "High: service cannot be used"
      ]
    }
  }
}
curl http://localhost:3000/v1/decision \
  -H "Content-Type: application/json" \
  --data-binary @request.json

GAISe applies the configured TypeSafe key to the upstream Bearer authorization header. The local request uses the GAISe model name and request shape.

Illustrative response (values are examples, not a live prediction):

{
  "model": "jev-1.13.0",
  "answers": {
    "urgent": {
      "type": "noul",
      "noul": 0.92
    },
    "team": {
      "type": "choice",
      "choice": "billing",
      "probabilities": {
        "billing": 0.95,
        "technical": 0.05
      },
      "confidence": 0.71
    },
    "severity": {
      "type": "score",
      "score": 1.2,
      "legend": {
        "0": "Low: minor inconvenience",
        "1": "Medium: a problem needing attention",
        "2": "High: service cannot be used"
      },
      "probabilities": {
        "0": 0.1,
        "1": 0.6,
        "2": 0.3
      },
      "confidence": 0.18
    }
  },
  "usage": {
    "input": {
      "input_tokens": 123
    },
    "output": {
      "output_tokens": 0
    }
  }
}

Upstream usage.input_tokens maps to usage.input.input_tokens, and usage.output_tokens maps to usage.output.output_tokens. Zero counts remain zero. GAISe does not invent a total counter. Scores, probabilities, confidence, and score legends remain typed JSON values.

Configuration

Setting Purpose
GaiseClientConfig.typesafe_api_key TypeSafe API key for library callers
GaiseClientConfig.typesafe_api_url Optional API root; default https://api.typesafe.ai, without /v1
TYPESAFE_API_KEY API key read by the gaise-api executable
TYPESAFE_API_URL API root read by the executable; takes precedence over TYPESAFE_BASE_URL
connection.api_key / connection.api_url Optional per-request overrides; each supplied field wins over service configuration
correlation_id Optional identifier used by GAISe request/response logging

Library callers supply configuration explicitly; environment variables are loaded by the server executable. The typesafe feature is enabled by default in gaise-client; use default-features = false, features = ["typesafe"] to select just this provider. Connection and correlation metadata are not sent in the upstream JSON body. GAISe redacts connection credentials before request logging.

Discovery and supported operations

GET /v1/models?provider=typesafe&operation=decision
GET /v1/models/typesafe::jev
GET /v1/models/limits?provider=typesafe&operation=decision

The first two routes query the provider catalog. The limits route reads GAISe's bundled registry and needs no provider credentials. GaiseOperation::Decision is serialized as decision; decision is also the Rust method name, and the HTTP path is /v1/decision.

Before 4.0 this operation was called System One. POST /v1/systemone, operation=system_one, GaiseClient::system_one, GaiseSystemOneRequest, GaiseSystemOneResponse, and GaiseOperation::SystemOne remain as deprecated aliases. Model listings now report the operation as decision. TypeSafe's own API keeps the System One name, so the adapter still calls its /v1/systemone.

Jev uses this typed decision operation. Text generation (instruct), SSE streaming, embeddings, tool calling, and live audio are not implemented for this provider. Give it text or structured context instead of image/audio attachments.

Validation and errors

GAISe validates a nonempty model and question map, nonempty Choice criteria, and at least two Score levels. It accepts strings, objects, arrays, or null for state and instruction/criterion descriptions, following the official SDK; useful context and explicit instructions are recommended. The provider can apply additional validation. Answer IDs and types must match the submitted questions.

The HTTP endpoint returns 400 for GAISe request validation failures. Axum rejects malformed JSON or incompatible field types before the handler. Provider, configuration, and transport failures currently return 500 with an error message; upstream status codes are included in provider error messages, not forwarded as the GAISe HTTP status.

Each upstream attempt has a 30-second timeout. HTTP 429 and 5xx responses, including 529, are retried twice using 500/1000ms backoff, or a numeric Retry-After delay capped at 60 seconds. Transport errors and other HTTP statuses are returned without retrying. There is no Decision streaming endpoint.

References: TypeSafe API, question types, and the official SDK contracts.