Servers

Define server URLs and transport mechanisms for your JSON-RPC API

OpenRPC allows you to specify one or more server configurations that define how clients can connect to your JSON-RPC API.

openrpc.yml
1servers:
2 - name: production
3 url: https://api.yourcompany.com/rpc
4 description: Production HTTP JSON-RPC server
5 - name: websocket
6 url: wss://api.yourcompany.com/rpc
7 description: Production WebSocket JSON-RPC server

Specifying servers is valuable for both SDKs and Docs:

  • For SDKs, your users won’t need to manually specify the server URL at client instantiation
  • For Docs, your API playground will automatically connect to the correct server

Transport protocols

JSON-RPC can be used over various transport protocols:

HTTP/HTTPS Transport

openrpc.yml
1servers:
2 - name: http-production
3 url: https://api.yourcompany.com/rpc
4 description: HTTPS JSON-RPC endpoint
5 - name: http-staging
6 url: https://staging-api.yourcompany.com/rpc
7 description: Staging HTTPS endpoint

WebSocket Transport

openrpc.yml
1servers:
2 - name: websocket-production
3 url: wss://api.yourcompany.com/rpc
4 description: WebSocket JSON-RPC for real-time communication
5 - name: websocket-dev
6 url: ws://localhost:8080/rpc
7 description: Development WebSocket server

TCP Transport

openrpc.yml
1servers:
2 - name: tcp-production
3 url: tcp://api.yourcompany.com:9090
4 description: TCP JSON-RPC server for high-performance applications

Server variables

Use variables to make your server configurations more flexible:

openrpc.yml
1servers:
2 - name: production
3 url: https://{environment}.api.yourcompany.com/rpc
4 description: Production JSON-RPC server
5 variables:
6 environment:
7 default: prod
8 enum:
9 - prod
10 - staging
11 - dev
12 description: Environment name

Multiple environments

Configure different environments with appropriate descriptions:

openrpc.yml
1servers:
2 - name: production
3 url: https://api.yourcompany.com/rpc
4 description: Production environment - high availability, rate limited
5 - name: staging
6 url: https://staging-api.yourcompany.com/rpc
7 description: Staging environment - for testing new features
8 - name: development
9 url: http://localhost:8080/rpc
10 description: Local development server
11 - name: sandbox
12 url: https://sandbox-api.yourcompany.com/rpc
13 description: Sandbox environment - safe for testing

Server-specific configurations

Add server-specific metadata and configurations:

openrpc.yml
1servers:
2 - name: production
3 url: https://api.yourcompany.com/rpc
4 description: Production JSON-RPC server
5 variables:
6 version:
7 default: v1
8 enum: [v1, v2]
9 description: API version
10 summary: High-performance production server
11 tags:
12 - name: production
13 description: Production environment

Load balancing and multiple URLs

Configure multiple server URLs for load balancing:

openrpc.yml
1servers:
2 - name: primary
3 url: https://api-primary.yourcompany.com/rpc
4 description: Primary production server
5 - name: secondary
6 url: https://api-secondary.yourcompany.com/rpc
7 description: Secondary production server (fallback)
8 - name: regional-us
9 url: https://us.api.yourcompany.com/rpc
10 description: US regional server
11 - name: regional-eu
12 url: https://eu.api.yourcompany.com/rpc
13 description: EU regional server

WebSocket-specific configurations

Configure WebSocket servers with connection parameters:

openrpc.yml
1servers:
2 - name: websocket-main
3 url: wss://api.yourcompany.com/rpc
4 description: Main WebSocket JSON-RPC server
5 variables:
6 protocol:
7 default: "jsonrpc-2.0"
8 description: JSON-RPC protocol version
9 heartbeat:
10 default: "30"
11 description: Heartbeat interval in seconds

Security configurations

Configure authentication and security at the server level:

openrpc.yml
1servers:
2 - name: secure-production
3 url: https://api.yourcompany.com/rpc
4 description: Secure production server with authentication
5 security:
6 - bearerAuth: []
7 - apiKeyAuth: []
8components:
9 securitySchemes:
10 bearerAuth:
11 type: http
12 scheme: bearer
13 apiKeyAuth:
14 type: apiKey
15 in: header
16 name: X-API-Key

Transport-specific optimizations

Configure servers for specific use cases:

openrpc.yml
1servers:
2 - name: bulk-operations
3 url: https://bulk.api.yourcompany.com/rpc
4 description: Optimized for batch requests and bulk operations
5 - name: real-time
6 url: wss://realtime.api.yourcompany.com/rpc
7 description: WebSocket server optimized for real-time notifications
8 - name: analytics
9 url: https://analytics.api.yourcompany.com/rpc
10 description: Dedicated server for analytics and reporting methods

Server configurations help clients understand how to connect to your JSON-RPC API and which transport mechanism is most appropriate for their use case.