Timeouts
Soxom supports configurable request timeouts at global, per-operation, and runtime levels.
Timeout Types
Section titled “Timeout Types”| Type | Description | Default |
|---|---|---|
default_ms | Total request timeout | 60000ms (1 min) |
connect_ms | Connection establishment | 10000ms (10 sec) |
read_ms | Time to first byte | 30000ms (30 sec) |
Configuration
Section titled “Configuration”Global Settings
Section titled “Global Settings”timeouts: # Total request timeout (milliseconds) default_ms: 60000 # 60 seconds
# Connection timeout connect_ms: 10000 # 10 seconds
# Read timeout (time to first byte) read_ms: 30000 # 30 seconds
# Per-operation overrides operations: batch_process: default_ms: 300000 # 5 minutes reports_generate: default_ms: 120000 # 2 minutes upload_file: default_ms: 600000 # 10 minutesTimeout Behavior
Section titled “Timeout Behavior”┌─────────────────────────────────────────────────────────────────┐│ Total Timeout (default_ms) │├────────────────┬────────────────────────────────────────────────┤│ Connect │ Read + Transfer ││ (connect_ms) │ │├────────────────┼─────────────────┬──────────────────────────────┤│ TCP/TLS │ First Byte │ Response Body ││ Handshake │ (read_ms) │ │└────────────────┴─────────────────┴──────────────────────────────┘- Connect timeout: Time allowed to establish TCP/TLS connection
- Read timeout: Time to receive first byte after sending request
- Total timeout: Overall limit for entire request lifecycle
Per-Operation Configuration
Section titled “Per-Operation Configuration”Use x-soxom-timeout in your OpenAPI spec:
paths: /reports/generate: post: x-soxom-timeout: 120000 # 2 minutes summary: Generate a report responses: "202": description: Report generation started
/batch/import: post: x-soxom-timeout: 300000 # 5 minutes summary: Import batch data
/files/upload: post: x-soxom-timeout: 600000 # 10 minutes summary: Upload a fileRuntime Override
Section titled “Runtime Override”Override timeout per-request:
// Override timeout for a single requestconst report = await client.reports.generate(params, { timeout: 120000 // 2 minutes});
// Very long operationconst result = await client.batch.process(data, { timeout: 600000 // 10 minutes});# Override timeout for a single requestreport = client.reports.generate( params, timeout=120000 # 2 minutes)
# Very long operationresult = client.batch.process( data, timeout=600000 # 10 minutes)// Use context with timeoutctx, cancel := context.WithTimeout(ctx, 2*time.Minute)defer cancel()
report, err := client.Reports.Generate(ctx, params)Client-Level Configuration
Section titled “Client-Level Configuration”Set default timeout when creating the client:
const client = new Client({ token: process.env.API_TOKEN, timeout: 30000, // 30 seconds default});client = Client( token=os.environ["API_TOKEN"], timeout=30000, # 30 seconds default)client := mysdk.NewClient( mysdk.WithToken(os.Getenv("API_TOKEN")), mysdk.WithTimeout(30 * time.Second),)Configuration Hierarchy
Section titled “Configuration Hierarchy”Timeout settings follow this precedence (highest to lowest):
- Runtime - Per-request timeout option
- Client - Client configuration
- Per-operation -
x-soxom-timeoutin OpenAPI - Global -
timeoutsin soxom.yaml - Defaults - Soxom built-in defaults
Common Patterns
Section titled “Common Patterns”Fast Endpoints
Section titled “Fast Endpoints”For simple CRUD operations:
timeouts: default_ms: 30000 # 30 seconds connect_ms: 5000 # 5 seconds read_ms: 10000 # 10 secondsLong-Running Operations
Section titled “Long-Running Operations”For batch processing, exports, etc.:
timeouts: default_ms: 60000
operations: batch_process: default_ms: 300000 export_data: default_ms: 600000File Uploads
Section titled “File Uploads”For large file transfers:
timeouts: operations: upload_file: default_ms: 1800000 # 30 minutes connect_ms: 10000 read_ms: 60000Error Handling
Section titled “Error Handling”Timeout errors are specific error types:
import { TimeoutError } from 'my-sdk';
try { await client.reports.generate(params);} catch (error) { if (error instanceof TimeoutError) { console.log("Request timed out"); // Retry with longer timeout await client.reports.generate(params, { timeout: 300000 }); }}from my_sdk import TimeoutError
try: client.reports.generate(params)except TimeoutError: print("Request timed out") # Retry with longer timeout client.reports.generate(params, timeout=300000)Best Practices
Section titled “Best Practices”- Set reasonable defaults - Most API calls should complete in under 30 seconds
- Increase for specific operations - Batch, upload, export operations need more time
- Use per-operation config for predictable slow endpoints
- Handle timeout errors gracefully in your application