| Crates.io | systemprompt-client |
| lib.rs | systemprompt-client |
| version | 0.0.11 |
| created_at | 2026-01-21 17:22:05.113736+00 |
| updated_at | 2026-01-25 21:41:46.174391+00 |
| description | HTTP API client library for systemprompt.io - enables TUI and external clients to communicate with the server |
| homepage | https://systemprompt.io |
| repository | https://github.com/systempromptio/systemprompt-core |
| max_upload_size | |
| id | 2059727 |
| size | 87,836 |
HTTP API client library for systemprompt.io - enables TUI and external clients to communicate with the server.
Part of the Shared layer in the systemprompt.io architecture.
This crate provides a type-safe, async HTTP client for interacting with the systemprompt.io API. It serves as the primary interface for external applications (TUI, CLI tools, third-party integrations) to communicate with the systemprompt.io server without depending on internal business logic.
systemprompt-identifiers for typed IDs (ContextId, JwtToken)thiserror for clear failure modesreqwest and tokio for non-blocking I/Osrc/
├── lib.rs # Crate root - public API exports
├── client.rs # SystempromptClient struct and all API methods
├── error.rs # ClientError enum and ClientResult type alias
└── http.rs # Internal HTTP helper functions (get, post, put, delete)
lib.rsMinimal public interface exposing only:
SystempromptClient - the main client structClientError - error enum for all failure modesClientResult<T> - type alias for Result<T, ClientError>client.rsThe core client implementation containing:
new(), with_timeout(), with_token()set_token(), token()list_agents(), get_agent_card()list_contexts(), get_context(), create_context(), delete_context(), update_context_name(), fetch_or_create_context(), create_context_auto_name()list_tasks(), delete_task()list_artifacts(), list_all_artifacts()send_message() (JSON-RPC format)list_logs(), list_users(), get_analytics()check_health(), verify_token()error.rsComprehensive error handling with variants:
| Variant | Description |
|---|---|
HttpError |
Network/transport failures (wraps reqwest::Error) |
ApiError |
Server returned non-2xx response with status and body |
JsonError |
Response body failed to deserialize |
AuthError |
Authentication/authorization failures |
NotFound |
Requested resource does not exist |
Timeout |
Request exceeded time limit |
ServerUnavailable |
Server unreachable |
ConfigError |
Invalid client configuration |
Other |
Catch-all for unexpected errors |
Includes is_retryable() helper for retry logic.
http.rsInternal module providing low-level HTTP operations:
get<T>() - GET request with optional auth, returns deserialized responsepost<T, B>() - POST with JSON body, returns deserialized responseput<B>() - PUT with JSON body, returns unitdelete() - DELETE request, returns unitAll functions handle authorization headers and error response parsing uniformly.
use systemprompt_client::{SystempromptClient, ClientResult};
use systemprompt_identifiers::JwtToken;
#[tokio::main]
async fn main() -> ClientResult<()> {
// Create client with authentication
let token = JwtToken::new("your-jwt-token");
let client = SystempromptClient::new("https://api.systemprompt.io")?
.with_token(token);
// List available agents
let agents = client.list_agents().await?;
for agent in agents {
println!("Agent: {}", agent.name);
}
// Work with contexts
let contexts = client.list_contexts().await?;
if let Some(ctx) = contexts.first() {
let tasks = client.list_tasks(ctx.context_id.as_ref()).await?;
println!("Found {} tasks", tasks.len());
}
// Health check (non-failing)
if client.check_health().await {
println!("Server is healthy");
}
Ok(())
}
| Category | Methods |
|---|---|
| Agents | list_agents, get_agent_card |
| Contexts | list_contexts, get_context, create_context, create_context_auto_name, fetch_or_create_context, update_context_name, delete_context |
| Tasks | list_tasks, delete_task |
| Artifacts | list_artifacts, list_all_artifacts |
| Messages | send_message |
| Admin | list_logs, list_users, get_analytics |
| Health | check_health, verify_token |
All fallible operations return ClientResult<T>. Pattern match on ClientError for specific handling:
use systemprompt_client::{ClientError, ClientResult};
async fn handle_errors(client: &SystempromptClient) -> ClientResult<()> {
match client.list_agents().await {
Ok(agents) => { /* success */ }
Err(ClientError::AuthError(msg)) => {
eprintln!("Authentication failed: {}", msg);
}
Err(ClientError::ApiError { status, message, .. }) => {
eprintln!("API error {}: {}", status, message);
}
Err(e) if e.is_retryable() => {
// Implement retry logic
}
Err(e) => return Err(e),
}
Ok(())
}
| Crate | Purpose |
|---|---|
reqwest |
HTTP client with async support |
tokio |
Async runtime |
serde / serde_json |
JSON serialization |
chrono |
DateTime handling for auto-naming |
thiserror |
Derive macro for error types |
anyhow |
Error wrapping for Other variant |
tracing |
Structured logging for error diagnostics |
systemprompt-models |
Shared API types (AgentCard, Task, etc.) |
systemprompt-identifiers |
Typed identifiers (ContextId, JwtToken) |
Default timeout is 30 seconds. Custom timeout:
let client = SystempromptClient::with_timeout("https://api.example.com", 60)?;
Token can be set at construction or later:
// At construction (builder pattern)
let client = SystempromptClient::new(url)?.with_token(token);
// After construction (mutation)
let mut client = SystempromptClient::new(url)?;
client.set_token(token);
FSL-1.1-ALv2 - See LICENSE for details.