Rust SDK Configuration
Configuration for the Tenzro Platform Rust SDK is handled through the TenzroConfig struct. It can be constructed directly with an API key and tenant ID, or loaded from environment variables. Both constructors support chained builder methods for overriding the network, base URL, and timeout.
TenzroConfig Struct
The TenzroConfig struct holds all connection parameters for the SDK:
pub struct TenzroConfig {
pub api_key: String, // format: tnz_{tenant}_{secret}
pub tenant_id: String,
pub network: Network, // Devnet | Testnet | Mainnet (default: Devnet)
pub base_url: String, // default: "https://api.platform.tenzro.com"
pub timeout_ms: u64, // default: 30_000
}Network Enum
The Network enum selects which GSF network the SDK connects to. Devnet is the default.
pub enum Network {
Devnet, // GSF DevNet (default)
Testnet, // GSF TestNet
Mainnet, // GSF MainNet
}Construction Methods
Direct Construction
Use TenzroConfig::new(api_key, tenant_id) to create a configuration with explicit values. This sets the network to Devnet, the base URL to https://api.platform.tenzro.com, and the timeout to 30_000 ms.
use tenzro_platform::TenzroConfig;
let config = TenzroConfig::new("tnz_mycompany_xxxxxxxxxxxx", "mycompany");From Environment Variables
Use TenzroConfig::from_env() to load configuration from the process environment. TENZRO_API_KEY is the only required variable; all others have defaults (see the table below).
use tenzro_platform::TenzroConfig;
let config = TenzroConfig::from_env();Chained Builder Methods
Both constructors return Self by value, so you can chain any combination of the three builder methods to override individual settings:
use tenzro_platform::{TenzroConfig, Network};
let config = TenzroConfig::new("tnz_mycompany_xxxxxxxxxxxx", "mycompany")
.with_network(Network::Mainnet)
.with_base_url("https://api.platform.tenzro.com")
.with_timeout(60_000);| Method | Parameter | Description |
|---|---|---|
.with_network(network) | Network | Set the target network (Devnet, Testnet, or Mainnet). |
.with_base_url(url) | &str | Override the API base URL. |
.with_timeout(ms) | u64 | Set the request timeout in milliseconds. |
Creating TenzroPlatform
TenzroPlatform is the main entry point to the SDK. All three constructors return Result<Self>, so they should be unwrapped or propagated with ?.
Direct construction
use tenzro_platform::TenzroPlatform;
let platform = TenzroPlatform::new("tnz_mycompany_xxxxxxxxxxxx", "mycompany")?;From a TenzroConfig
Pass a fully customised TenzroConfig to TenzroPlatform::from_config(config):
use tenzro_platform::{TenzroPlatform, TenzroConfig, Network};
let config = TenzroConfig::new("tnz_mycompany_xxxxxxxxxxxx", "mycompany")
.with_network(Network::Testnet)
.with_timeout(60_000);
let platform = TenzroPlatform::from_config(config)?;From environment variables
use tenzro_platform::TenzroPlatform;
let platform = TenzroPlatform::from_env()?;Environment Variables
The following environment variables are read by TenzroConfig::from_env() and TenzroPlatform::from_env():
| Variable | Required | Default | Description |
|---|---|---|---|
TENZRO_API_KEY | Yes | — | API key in the format tnz_tenant_secret. The tenant segment is extracted automatically if TENZRO_TENANT_ID is not set. |
TENZRO_TENANT_ID | No | Extracted from TENZRO_API_KEY | Explicit tenant identifier. Overrides the tenant extracted from the API key. |
TENZRO_NETWORK | No | devnet | Target network. Recognised values: mainnet, main, production, prod (all resolve to Mainnet); testnet, test, staging (Testnet). Any other value defaults to Devnet. |
TENZRO_BASE_URL | No | https://api.platform.tenzro.com | Override the API base URL. |
TENZRO_TIMEOUT_MS | No | 30000 | Request timeout in milliseconds. |
API Key Format
API keys follow the pattern tnz_tenant_secret, for example:
tnz_mycompany_xxxxxxxxxxxxxxxxxxxxThe middle segment (mycompany in the example above) is the tenant identifier. When TENZRO_TENANT_ID is not provided, the SDK splits the key on _ and uses that segment automatically.
Network Selection
The network can be set programmatically via the Network enum:
use tenzro_platform::{TenzroConfig, Network};
// Devnet (default — no call to with_network needed)
let config = TenzroConfig::new("tnz_mycompany_xxxxxxxxxxxx", "mycompany");
// Testnet
let config = TenzroConfig::new("tnz_mycompany_xxxxxxxxxxxx", "mycompany")
.with_network(Network::Testnet);
// Mainnet
let config = TenzroConfig::new("tnz_mycompany_xxxxxxxxxxxx", "mycompany")
.with_network(Network::Mainnet);Or by setting the environment variable before your process starts:
TENZRO_NETWORK=mainnetMultiple Tenants
Create a separate TenzroPlatform instance for each tenant. Because TenzroConfig is a plain struct, constructing multiple instances is straightforward:
use tenzro_platform::{TenzroPlatform, TenzroConfig, Network};
let platform1 = TenzroPlatform::from_config(
TenzroConfig::new("tnz_tenant1_xxxxxxxxxxxx", "tenant1")
.with_network(Network::Mainnet),
)?;
let platform2 = TenzroPlatform::from_config(
TenzroConfig::new("tnz_tenant2_xxxxxxxxxxxx", "tenant2")
.with_network(Network::Mainnet),
)?;Complete Example
use tenzro_platform::{TenzroPlatform, TenzroConfig, Network};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Option 1: from environment variables
let platform = TenzroPlatform::from_env()?;
// Option 2: direct construction (network defaults to Devnet)
let platform = TenzroPlatform::new("tnz_mycompany_xxxxxxxxxxxx", "mycompany")?;
// Option 3: via TenzroConfig for full control
let config = TenzroConfig::new("tnz_mycompany_xxxxxxxxxxxx", "mycompany")
.with_network(Network::Mainnet)
.with_timeout(60_000);
let platform = TenzroPlatform::from_config(config)?;
Ok(())
}