Implementing an ORS Server
This guide shows how to implement an ORS server, either using the Python SDK or from scratch in any language.Two Approaches
Option 1: Use OpenReward Python SDK
Pros: Fast, handles protocol details, well-tested Cons: Python onlyOption 2: Implement HTTP Protocol
Pros: Any language, full control, no dependencies Cons: More work, must handle all protocol detailsOption 1: Python SDK Implementation
Basic Structure
Key Methods
list_splits(cls) - Required:
- Class method (no instance needed)
- Returns list of split names or Split objects
- Example:
return ["train", "validation", "test"]
list_tasks(cls, split) - Required:
- Class method
- Returns list of task objects (JSON)
- Task structure is environment-specific
get_prompt(self) - Required:
- Instance method (has access to
self.task_spec) - Returns Blocks (list of TextBlock/ImageBlock)
- Called once per episode
setup(self) - Optional:
- Called when episode starts
- Initialize environment state
- Can be async
teardown(self) - Optional:
- Called when episode ends
- Cleanup resources
- Can be async
Tool Decorator
- Decorated with
@tool - Takes
selfand one Pydantic model parameter - Returns
ToolOutput - Can be async
Complete Example
See Quick Start for a working GSM8K environment.Option 2: Custom HTTP Implementation
Required Endpoints
Implement these HTTP endpoints: Discovery (no auth):GET /healthGET /list_environmentsGET /{env_name}/toolsGET /{env_name}/splitsPOST /{env_name}/tasks
POST /create_sessionPOST /createPOST /deletePOST /ping
GET /{env_name}/promptPOST /{env_name}/call(returns SSE stream)
Example: Node.js/TypeScript
Session Management
Key points:- Store session ID → environment instance mapping
- Implement 15-minute timeout
- Clean up on
/delete - Handle concurrent sessions
Error Handling
Return proper HTTP status codes:400- Bad request (invalid input)404- Not found (session, tool, environment)500- Server error
error event.
Best Practices
1. Validate Inputs
2. Use Type Hints
3. Handle Async Operations
4. Implement Proper Cleanup
5. Add Logging
Testing Your Server
See Testing Locally for comprehensive testing guide. Quick test:Deployment
Local Development
Production Deployment
Docker:Cloud Deployment
Deploy to any cloud platform:- AWS: ECS, Lambda, EC2
- GCP: Cloud Run, Compute Engine
- Azure: Container Instances, App Service
- Fly.io:
fly launch - Railway: Connect GitHub repo
Next Steps
Testing Locally
Test your ORS server thoroughly
HTTP API
Complete endpoint documentation
Quick Start
See a complete working example
Key Takeaway: Implementing an ORS server is straightforward. Use the Python SDK for quick development, or implement the HTTP protocol in any language for full control. Focus on proper reward design and episode termination.

