Freebuff2API

repository·main·Indexed 17 days ago

https://github.com/quorinex/freebuff2api

An OpenAI-compatible proxy server for Freebuff that translates standard OpenAI API requests into Freebuff's backend format. It features stealth request handling with randomized client fingerprints, automatic multi-token rotation, and HTTP proxy support. The server provides endpoints for chat completions and Claude-compatible messages, managing model-to-agent mappings via a ModelRegistry.

Tokens
4.8K
Snippets
20
Records
30
Agent score
67%

What's inside Freebuff2API

  1. Overview of Freebuff2API

    main

    Freebuff2API is an OpenAI-compatible proxy server for Freebuff. It translates standard OpenAI API requests into Freebuff's backend format, enabling the use of Freebuff's free models with any OpenAI-compatible client, SDK, or CLI tool.

    Key features include:

    • OpenAI Compatible API: Works with standard OpenAI endpoints.
    • Stealth Request Handling: Uses dynamic, randomized client fingerprints to mimic official Freebuff SDK behavior.
    • Multi-Token Rotation: Automatically cycles through multiple auth tokens at a configurable interval.
    • HTTP Proxy Support: Allows routing outbound traffic through an upstream proxy.
  2. What is Freebuff2API

    main

    Freebuff2API is an OpenAI-compatible proxy server for Freebuff. It converts standard OpenAI API requests into the Freebuff backend format, allowing you to use Freebuff's free models with any OpenAI-compatible client, SDK, or command-line tool.

    Core Features:

    • OpenAI Compatible API: Standard endpoints that work out-of-the-box with compatible clients.
    • High Stealth Request Handling: Uses dynamic random client identifiers to simulate official Freebuff SDK behavior.
    • Multi-Token Rotation: Supports multiple authentication tokens with a built-in automatic rotation mechanism.
    • HTTP Proxy Support: Allows configuring an upstream HTTP proxy for all external requests.
  3. Get Freebuff Auth Tokens

    main

    Freebuff2API requires at least one Freebuff Auth Token. You can obtain tokens using one of two methods:

    1. Visit https://freebuff.llm.pm.
    2. Log in with your Freebuff account.
    3. Your Auth Token will be displayed on the page. Copy this value to use as AUTH_TOKENS.

    Method 2: Freebuff CLI

    1. Install the CLI globally:
      npm i -g freebuff
    2. Run freebuff in your terminal and follow the login prompts.
    3. Locate the authToken in your local credentials file:
      • Windows: C:\\Users\\<Username>>>\.config\\manicode\\credentials.json
      • Linux / macOS: ~/.config/manicode/credentials.json

    Tip: You can log in with multiple accounts and provide all tokens to increase concurrent throughput.

    npm i -g freebuff
  4. Deploy Freebuff2API via Docker

    main

    You can run Freebuff2API using pre-built multi-arch images from GHCR or by building the image manually.

    Run pre-built image:

    docker run -d --name Freebuff2API \
      -p 8080:8080 \
      -e AUTH_TOKENS="token1,token2" \
      ghcr.io/quorinex/freebuff2api:latest

    Manual build and run:

    docker build -t Freebuff2API .
    docker run -d -p 8080:8080 -e AUTH_TOKENS="token1,token2" Freebuff2API
  5. Obtain Freebuff Auth Tokens

    main

    Freebuff2API requires one or more Freebuff auth tokens. You can obtain them using one of two methods:

    1. Visit https://freebuff.llm.pm.
    2. Log in with your Freebuff account.
    3. Copy the auth token displayed on the page.

    Method 2: Freebuff CLI

    1. Install the CLI: npm i -g freebuff.
    2. Run freebuff and follow the login prompts.
    3. Locate your token in the local credentials file:
      • Windows: C:\\Users\\<username>\\.config\\manicode\\credentials.json
      • Linux / macOS: ~/.config/manicode/credentials.json
    4. Extract the authToken value from the JSON file.
    {
      "default": {
        "id": "user_10293847",
        "name": "Zhang San",
        "email": "zhangsan@example.com",
        "authToken": "fa82b5c1-e39d-4c7a-961f-d2b3c4e5f6a7",
        ...
      }
    }
  6. Deploy Freebuff2API using Docker

    main

    You can run Freebuff2API using pre-built multi-arch images from GHCR or by building from source.

    Run pre-built image

    docker run -d --name Freebuff2API \
      -p 8080:8080 \
      -e AUTH_TOKENS="token1,token2" \
      ghcr.io/quorinex/freebuff2api:latest

    Build and run from source

    docker build -t Freebuff2API .
    docker run -d -p 8080:8080 -e AUTH_TOKENS="token1,token2" Freebuff2API
  7. Configure Freebuff2API

    main

    Configuration is managed via a config.json file in the working directory or through environment variables. Environment variables override JSON values. You can specify a custom config path using the -config flag.

    Configuration Keys Reference

    Key / Env VarDescription
    LISTEN_ADDRProxy listen address (default :8080)
    UPSTREAM_BASE_URLFreebuff backend URL (default https://codebuff.com)
    AUTH_TOKENSFreebuff auth tokens (JSON array or comma-separated env var)
    ROTATION_INTERVALRun rotation interval (default 6h)
    REQUEST_TIMEOUTUpstream request timeout (default 15m)
    API_KEYSClient API keys for proxy auth (empty = open access)
    HTTP_PROXYHTTP proxy for outbound requests
    {
      "LISTEN_ADDR": ":8080",
      "UPSTREAM_BASE_URL": "https://codebuff.com",
      "AUTH_TOKENS": ["eyJhb..."],
      "ROTATION_INTERVAL": "6h",
      "REQUEST_TIMEOUT": "15m",
      "API_KEYS": [],
      "HTTP_PROXY": ""
    }
  8. How the proxy handles tool schemas

    main

    To ensure compatibility with upstream providers that may have stricter JSON Schema requirements, the server performs Tool Schema Normalization.

    When a request contains a tools array, the server:

    1. Resolves local $ref pointers (supporting both #/definitions/ and #/$defs/).
    2. Simplifies anyOf and oneOf combinators by removing null types.
    3. Flattens type arrays into a single primitive type (preferring the first non-null type).
    4. Cleans up enum, const, and nullable fields to match a conservative subset of JSON Schema.

    This allows clients like LobeChat, which emit complex schemas, to work seamlessly with the proxy.

  9. Configure the Freebuff2API proxy server

    main

    The proxy server is configured using a combination of a JSON configuration file and environment variables. Environment variables take precedence over values defined in the JSON file.

    Configuration Options

    KeyTypeDescription
    LISTEN_ADDRstringThe address the proxy server listens on (e.g., :8080).
    UPSTREAM_BASE_URLstringThe base URL of the upstream service. If set to codebuff.com, it is automatically normalized to www.codebuff.com.
    AUTH_TOKENSCSV stringA comma-separated or newline-separated list of valid authentication tokens.
    ROTATION_INTERVALdurationThe interval for token rotation (e.g., 6h). Must be greater than zero.
    REQUEST_TIMEOUTdurationThe timeout for upstream requests (e.g., 15m). Must be greater than zero.
    API_KEYSCSV stringA comma-separated or newline-separated list of API keys.
    HTTP_PROXYstringAn optional HTTP proxy URL to use for upstream requests.

    Default Values

    If not provided via file or environment, the following defaults are used:

    • LISTEN_ADDR: :8080
    • UPSTREAM_BASE_URL: https://www.codebuff.com
    • ROTATION_INTERVAL: 6h
    • REQUEST_TIMEOUT: 15m