Skip to content

Missing User-Agent header causes Cloudflare 403 on API requests #13

Description

@SAKURAAUA

Problem

API requests from OpenAICompatibleProvider are blocked by Cloudflare-protected endpoints (e.g. OpenCode Go) with HTTP 403, error code 1010.

Root Cause

The _request_headers() method in echobot/providers/openai_compatible.py:380 does not include a User-Agent header. Cloudflare interprets the request as coming from an automated bot and blocks it.

Steps to Reproduce

  1. Configure .env with a valid API key targeting any Cloudflare-protected OpenAI-compatible endpoint
  2. Start the bot
  3. Any LLM request fails with 401/403

Suggested Fix

Add a User-Agent header to the request headers:

def _request_headers(self) -> dict[str, str]:
    return {
        "Authorization": f"Bearer {self.settings.api_key}",
        "Content-Type": "application/json; charset=utf-8",
        "User-Agent": "EchoBot/1.0",
        **self.settings.extra_headers,
    }

This allows the request to pass Cloudflare's browser integrity check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions