graphql-transport-ws subprotocol to deliver
real-time data updates. By integrating Codex through Uniblock, you can access
low-latency market events and token tracking through a unified interface.
Endpoints
To integrate Codex, use the following endpoints for validation and streaming:- HTTP (Validation):
https://websocket.uniblock.dev/codex/validate - WebSocket (WSS):
wss://websocket.uniblock.dev/codex
Authentication
Uniblock supports two ways to authenticate your Codex WebSocket connection and validation requests:- Header: Include
x-api-key: YOUR_API_KEYin your request headers. - URL query parameter: Append
apiKey=YOUR_API_KEYto the connection string.
connection_init message payload under the Authorization
key.
Parameters
| Parameter | Required | Description |
|---|---|---|
apiKey / x-api-key | Yes | Your unique Uniblock API key. |
Validate connection
Before establishing a permanent socket, use the validation endpoint to verify your credentials. You can pass the API key in the URL or the header.Option 1: Header authentication
Header authentication is recommended to avoid exposing your API key in server
logs or URLs.
Option 2: URL authentication
Workflow
To successfully establish and maintain a stream, implement the connection using this operational flow:- Validate credentials: Send a GET request to the Codex HTTP validation endpoint using your preferred authentication method.
- Establish WebSocket connection: Connect to the WSS endpoint using the
graphql-transport-wssubprotocol. - Initialize session: Send a
connection_initpayload message containing your token authorization. - Acknowledge and subscribe: Wait for the server to reply with a
connection_ackmessage, then send your GraphQLsubscribepayload with a unique tracking identifier inid. - Unsubscribe or complete: When you want to stop receiving updates for a
specific stream, send a
completemessage matching the operationalid.
Protocol payloads
The Codex GraphQL WebSocket protocol exchanges structured JSON messages. Every payload must include atype property, and streaming operations require an
explicit id.
Initialize session
Send this message immediately after the WebSocket connection opens to pass credentials and authorize your session.Subscribe to streams
After receiving theconnection_ack message from the server, submit your
GraphQL subscription query. Assign a tracking value to the id property to
manage this specific stream.
Unsubscribe
To stop a running subscription without tearing down the entire WebSocket connection, send acomplete message targeting the original subscription id.
Connection heartbeat
Codex requires a continuous handshake sequence to monitor stream viability and keep idle connections open.Server ping
The server issues a periodicping payload to check client responsiveness.
Client pong
Your client must immediately listen for this message and reply with a matchingpong payload. Failure to respond will result in automated socket termination.
Pricing
Responses are billed using the shared WebSocket pricing formula:0.1 CU * 3,500per response returned