docs.rs failed to build sevensense-api-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
sevensense-api
HTTP API layer for the 7sense bioacoustic intelligence platform.
sevensense-api provides a comprehensive HTTP interface to all 7sense functionality. It offers GraphQL for flexible queries, REST endpoints with OpenAPI documentation, WebSocket streaming for real-time analysis, and Server-Sent Events for monitoring. Built on Axum for high performance and reliability.
Features
- GraphQL API: Flexible queries with async-graphql
- REST Endpoints: OpenAPI/Swagger documented
- WebSocket Streaming: Real-time audio analysis
- Authentication: JWT-based auth with refresh tokens
- Rate Limiting: Configurable request throttling
- Health Checks: Kubernetes-ready probes
Use Cases
| Use Case | Description | Endpoint |
|---|---|---|
| Species Identification | Identify birds from audio | POST /api/identify |
| Similarity Search | Find similar recordings | POST /api/search |
| Batch Processing | Process multiple files | POST /api/batch |
| Real-time Analysis | Stream audio for analysis | WS /ws/stream |
| Health Monitoring | Check system status | GET /health |
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
Starting the Server
# Start with default configuration
# With custom port
SEVENSENSE_PORT=8080
# With configuration file
API Endpoints
Once running, access:
- GraphQL Playground: http://localhost:3000/graphql
- Swagger UI: http://localhost:3000/docs/swagger-ui
- Health Check: http://localhost:3000/health
Basic Species Query
query {
identifySpecies(audioUrl: "https://example.com/bird.wav") {
predictions {
speciesId
commonName
scientificName
confidence
}
processingTime
}
}
Similarity Search
query SearchSimilar($embedding: [Float!]!, $k: Int!) {
searchSimilar(embedding: $embedding, k: $k, minSimilarity: 0.8) {
id
species {
scientificName
commonName
}
similarity
recordingUrl
timestamp
}
}
With Filters
query FilteredSearch {
searchSimilar(
embedding: [0.1, 0.2, ...]
k: 20
filter: {
species: ["Turdus merula", "Turdus philomelos"]
location: { lat: 51.5, lon: -0.1, radiusKm: 50 }
timeRange: { start: "2024-01-01", end: "2024-06-30" }
}
) {
id
species { commonName }
similarity
location { lat, lon, siteName }
}
}
Mutations
mutation AddRecording($input: RecordingInput!) {
addRecording(input: $input) {
id
status
embedding
}
}
mutation DeleteRecording($id: ID!) {
deleteRecording(id: $id) {
success
message
}
}
Subscriptions
subscription OnNewDetection {
newDetection(location: { lat: 51.5, lon: -0.1, radiusKm: 10 }) {
id
species { commonName }
confidence
timestamp
audioUrl
}
}
Species Identification
# From file upload
# From URL
Response:
Similarity Search
Batch Processing
Health Checks
# Liveness probe
# Readiness probe
# Detailed status
Connecting to Stream
const ws = ;
ws ;
ws ;
// Stream audio chunks
Rust Client
use ;
use connect_async;
async
Stream Protocol
| Message Type | Direction | Description |
|---|---|---|
start |
Client→Server | Start streaming with config |
audio |
Client→Server | Audio chunk (binary) |
stop |
Client→Server | Stop streaming |
detection |
Server→Client | Species detection event |
error |
Server→Client | Error message |
status |
Server→Client | Processing status |
JWT Authentication
# Login to get tokens
# Response
{
}
# Use access token
# Refresh token
API Keys
# Create API key
# Use API key
Scopes
| Scope | Description |
|---|---|
read |
Read-only access to search and identify |
write |
Add/modify recordings |
admin |
Administrative operations |
stream |
Real-time streaming access |
Configuration File
# config.toml
[]
= "0.0.0.0"
= 3000
= 4
[]
= "your-secret-key"
= 24
= 30
[]
= true
= 100
= 20
[]
= "postgres://user:pass@localhost/sevensense"
= 20
[]
= "./data/hnsw.index"
= true
[]
= "info"
= "json"
Environment Variables
# Server
# Authentication
# Database
# Logging
Programmatic Configuration
use ;
async
API Reference
GraphQL Schema
| Type | Description |
|---|---|
Query.identifySpecies |
Identify species from audio |
Query.searchSimilar |
Find similar recordings |
Query.getRecording |
Get recording by ID |
Mutation.addRecording |
Add new recording |
Subscription.newDetection |
Real-time detection events |
REST Endpoints
| Method | Path | Description |
|---|---|---|
POST |
/api/identify |
Identify species |
POST |
/api/search |
Similarity search |
POST |
/api/batch |
Batch processing |
GET |
/api/recordings/:id |
Get recording |
WS |
/ws/stream |
Real-time streaming |
Health Endpoints
| Path | Description |
|---|---|
/health/live |
Liveness probe |
/health/ready |
Readiness probe |
/health/status |
Detailed status |
Performance
| Metric | Target | Actual |
|---|---|---|
| Identify Latency | <200ms | ~150ms |
| Search Latency | <50ms | ~35ms |
| Concurrent Connections | 1000 | ✅ |
| Requests/Second | 500 | ~600 |
Links
- Homepage: ruv.io
- Repository: github.com/ruvnet/ruvector
- Crates.io: crates.io/crates/sevensense-api
- Documentation: docs.rs/sevensense-api
License
MIT License - see LICENSE for details.
Part of the 7sense Bioacoustic Intelligence Platform by rUv