Skip to main content

WebSocket Authentication

WebSocket connections require API key authentication for secure access to real-time news streams.

Authentication Method

WebSocket authentication uses your API key provided during the connection handshake.

API Key Setup

  1. Get Your API Key
    • Login to Byul API Dashboard
    • Your API key is displayed on the dashboard
    • API keys start with byul_v2_
  2. Connection Authentication

Authentication Flow

  1. Connection Request: Client connects with API key in auth options
  2. Server Validation: Server validates API key and plan permissions
  3. Authentication Success: Server emits auth:success event with user details
  4. Ready for Subscriptions: Client can now subscribe to news streams

Authentication Success Event

Success Response Structure:

Error Handling

Authentication Errors

Common Error Codes:
  • INVALID_API_KEY - API key is invalid or malformed
  • PLAN_REQUIRED - WebSocket access requires Pro/Enterprise plan
  • RATE_LIMITED - Too many authentication attempts
  • CONNECTION_LIMIT - Maximum connections exceeded for plan

Security Best Practices

Environment Variables

Never hardcode API keys in your source code. Use environment variables:

Production Configuration

API Key Protection

Backend Only: Keep API keys on your backend servers. Never expose them to client-side JavaScript in production. Key Rotation: Regularly rotate your API keys for enhanced security. Access Control: Restrict API key access to authorized team members only.

Connection Examples

Basic Authentication

With Reconnection

Python Authentication

Troubleshooting

Authentication Issues

Invalid API Key Format
  • Verify API key format from dashboard
  • Check for extra whitespace or characters
Plan Requirements
Connection Timeout
  • Check network connectivity
  • Verify firewall settings allow WebSocket connections
  • Try connecting from a different network

Testing Authentication

Test your authentication setup with a simple connection:

Next Steps

News Subscription

Subscribe to filtered news streams

Error Handling

Handle connection errors and implement retry logic

Connection Management

Advanced connection configuration and monitoring

Examples

Production-ready implementation examples