Skip to content

jyjeanne/crabrace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Crabrace πŸ¦€

Rust License: MIT

Rust port of Catwalk - AI Provider Database

   ___           _
  / __|_ _ __ _| |__ _ _ __ _ __ ___
 | (__| '_/ _` | '_ \ '_/ _` / _/ -_)
  \___|_| \__,_|_.__/_| \__,_\__\___|
         πŸ¦€ Fast β€’ Safe β€’ Reliable

A high-performance, memory-safe HTTP-based AI provider database service written in Rust. Rust port of Catwalk for the Crustly AI assistant.


πŸ“Š Overview

Crabrace is a centralized registry service for AI inference providers (LLMs) and their models. It provides:

  • βœ… Provider Metadata - Up-to-date information about 18 AI providers
  • βœ… Model Information - Costs, capabilities, context windows for 354+ models
  • βœ… RESTful API - Simple HTTP endpoints for querying
  • βœ… Production Ready - Docker, Kubernetes, configuration management
  • βœ… Observable - Built-in Prometheus metrics with Grafana dashboards
  • βœ… Flexible Config - Environment variables, TOML files, or both
  • βœ… Secure - CORS, security headers, non-root containers
  • βœ… High Performance - 25k+ req/s, <15ms P99 latency, comprehensive benchmarks

πŸš€ Quick Start

Installation

# Clone repository
git clone https://github.com/jyjeanne/crabrace.git
cd crabrace

# Build (See BUILD_WORKAROUND.md for Windows build issues)
cargo build --release

# Run
./target/release/crabrace

Usage

# Start server
crabrace
# Server starts on http://localhost:8080

# Query providers
curl http://localhost:8080/providers

# Health check
curl http://localhost:8080/health

# Metrics
curl http://localhost:8080/metrics

πŸ“š Documentation


πŸ—οΈ Architecture

HTTP Layer (Axum + Tokio)
    ↓
Provider Registry (Lazy Static)
    ↓
Embedded JSON Configs (16+ providers)
    ↓
Data Models (Serde)

Key Features:

  • Async/await with Tokio
  • Zero-cost abstractions
  • Compile-time safety
  • Embedded configurations
  • Memory efficient (~5MB idle)

πŸ”Œ API Endpoints

GET /providers

Returns all available AI providers and their models.

Response:

[
  {
    "name": "Anthropic",
    "id": "anthropic",
    "type": "anthropic",
    "models": [
      {
        "id": "claude-sonnet-4-5-20250929",
        "name": "Claude Sonnet 4.5",
        "cost_per_1m_in": 3.0,
        "cost_per_1m_out": 15.0,
        "context_window": 200000
      }
    ]
  }
]

GET /health

Health check endpoint.

Response: OK

GET /metrics

Prometheus metrics.


πŸ¦€ Why Rust?

Performance Comparison: Catwalk (Go) vs Crabrace (Rust)

Metric Catwalk (Go) Crabrace (Rust) Improvement
Startup Time ~120ms ~50ms 2.4x faster
Memory (idle) ~10MB ~6MB 40% less
Throughput ~10k req/s ~25k req/s 2.5x higher
P99 Latency ~25ms ~12ms 2x faster
Binary Size ~15MB ~8MB 47% smaller
Safety GC + Runtime Compile-time Zero runtime overhead

πŸ“Š Performance Testing

Crabrace includes comprehensive performance testing infrastructure:

Microbenchmarks

# Run Criterion benchmarks
cargo bench

# View detailed HTML reports
open target/criterion/report/index.html

Benchmark Coverage:

  • Provider loading and search operations
  • JSON serialization performance
  • HTTP client overhead

Load Testing

# Start server
cargo run --release &

# Run load tests
cd perf-tests
./load-test-bombardier.sh  # Cross-platform
./load-test-wrk.sh          # Linux/macOS
./load-test-ab.sh           # Apache Bench
./stress-test.sh            # Gradual load increase

Performance Targets:

  • Throughput: >25,000 req/s βœ…
  • P99 Latency: <15ms βœ…
  • Memory: <15MB under load βœ…
  • Zero errors under normal load βœ…

See Performance Testing and Benchmark Results for details.


πŸ”§ Development

Prerequisites

  • Rust 1.75 or later
  • Cargo

Build Commands

# Development build
cargo build

# Release build (optimized)
cargo build --release

# Small binary build
cargo build --profile release-small

# Run tests
cargo test

# Run benchmarks
cargo bench

# Lint code
cargo clippy

# Format code
cargo fmt

Project Structure

crabrace/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs              # HTTP server
β”‚   β”œβ”€β”€ client.rs            # HTTP client library
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── provider.rs      # Data models
β”‚   └── providers/
β”‚       β”œβ”€β”€ registry.rs      # Provider registry
β”‚       └── configs/         # JSON configurations
β”œβ”€β”€ tests/                   # Integration tests
β”œβ”€β”€ benches/                 # Benchmarks
└── docs/                    # Documentation

πŸ“¦ Supported Providers

All 18 Providers Implemented:

Cloud Providers

  • βœ… Anthropic (Claude)
  • βœ… OpenAI (GPT)
  • βœ… Google Gemini
  • βœ… Azure OpenAI
  • βœ… AWS Bedrock
  • βœ… VertexAI
  • βœ… xAI (Grok)
  • βœ… Zhipu AI (zAI)
  • βœ… GROQ
  • βœ… OpenRouter (206+ models)
  • βœ… Cerebras
  • βœ… Venice
  • βœ… Chutes
  • βœ… DeepSeek
  • βœ… HuggingFace
  • βœ… AIHubMix

Local Providers

  • βœ… Ollama - Run LLMs locally (Llama, Mistral, Phi, etc.)
  • βœ… LM Studio - Desktop app for local LLM inference

πŸ”— Integration

Use as Library

[dependencies]
crabrace = "0.1"
use crabrace::CrabraceClient;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = CrabraceClient::new();
    let providers = client.get_providers().await?;

    for provider in providers {
        println!("Provider: {}", provider.name);
    }

    Ok(())
}

🐳 Docker

Quick Start with Docker

# Build the image
docker build -t crabrace:latest .

# Run the container
docker run -d \
  --name crabrace \
  -p 8080:8080 \
  -e RUST_LOG=info \
  crabrace:latest

# Check logs
docker logs -f crabrace

# Test the API
curl http://localhost:8080/health
curl http://localhost:8080/providers

Docker Compose (Recommended)

Run Crabrace with Docker Compose for easier management:

# Start Crabrace only
docker-compose up -d

# Start with monitoring stack (Prometheus + Grafana)
docker-compose --profile monitoring up -d

# View logs
docker-compose logs -f crabrace

# Stop services
docker-compose down

# Stop and remove volumes
docker-compose down -v

Access Services:

Docker Image Details

Multi-Stage Build:

  • Builder stage: Rust 1.75 slim
  • Runtime stage: Debian Bookworm slim
  • Final image size: ~80MB

Features:

  • βœ… Non-root user for security
  • βœ… Health checks included
  • βœ… Optimized for production
  • βœ… Minimal dependencies

Configuration

Crabrace supports flexible configuration via environment variables, configuration files, or both.

Quick Configuration via Environment Variables:

Variable Default Description
CRABRACE_SERVER__HOST 0.0.0.0 Server bind address
CRABRACE_SERVER__PORT 8080 Server port
CRABRACE_LOGGING__LEVEL info Log level (trace, debug, info, warn, error)
CRABRACE_LOGGING__JSON_FORMAT false Use JSON logging
CRABRACE_METRICS__ENABLED true Enable metrics endpoint

Using Configuration File:

# Copy and edit example config
cp config.toml.example config.toml
nano config.toml

# Run with custom config
docker run -v $(pwd)/config.toml:/app/config.toml crabrace:latest

See Configuration Guide for complete documentation

Build Options

# Standard build
docker build -t crabrace:latest .

# Build with cache disabled
docker build --no-cache -t crabrace:latest .

# Build for specific platform
docker build --platform linux/amd64 -t crabrace:latest .

# Multi-platform build
docker buildx build --platform linux/amd64,linux/arm64 -t crabrace:latest .

🀝 Contributing

Contributions welcome! Please read CONTRIBUTING.md for guidelines.

Adding a New Provider

  1. Create JSON config in src/providers/configs/
  2. Add const declaration in src/providers/registry.rs
  3. Add load_provider!() call in load_providers() method
  4. Update test expectations in test_all_providers_loaded()
  5. Update README provider count
  6. Submit PR

πŸ“„ License

MIT License - see LICENSE for details


πŸ™ Acknowledgments

  • Catwalk - Original Go implementation
  • Charm - For the amazing Catwalk project
  • Crustly - Rust AI assistant that uses Crabrace

πŸ“Š Status

  • Version: 0.1.0 (Release Candidate)
  • Status: Phase 4 Complete - Production Ready
  • API Compatibility: 100% with Catwalk βœ…
  • Providers: 18 (16 cloud + 2 local) βœ…
  • Models: 354+ models across all providers
  • Production Ready: Docker βœ… | Config βœ… | Security βœ… | K8s βœ…

Progress

Phase Status Completion
Phase 1: Data Model βœ… Complete 100%
Phase 2: Infrastructure βœ… Complete 100%
Phase 3: Providers βœ… Complete 100%
Phase 4: Production βœ… Complete 100%

Phase 4: Production Readiness

Feature Status Notes
Docker Support βœ… Complete Multi-stage builds, docker-compose
Configuration Management βœ… Complete Env vars, TOML, validation
Security Hardening βœ… Complete CORS, security headers (rate limiting: TODO)
Kubernetes Manifests βœ… Complete kubectl, Kustomize, Helm charts
Performance Testing βœ… Complete Criterion benchmarks, load tests

Note: Rate limiting is temporarily disabled due to tower_governor 0.4.3 type compatibility issues. Will be re-enabled after upgrading to version 0.8.0+.


Built with πŸ¦€ Rust β€’ Ported from Catwalk (Go) β€’ Part of Crustly

About

A high-performance, memory-safe HTTP-based AI provider database service written in Rust

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors