OhMyGPT API
English
  • 中文
  • English
  • 日本語
OhMyGPT
OhMyGPT
English
  • 中文
  • English
  • 日本語
  1. Archive documents
  • Introduction to this site
  • Change log
  • OpenAI
    • Responses
      • Create model response
      • Get model response
      • Delete model response
      • Cancel response
      • List input items
    • Conversations
      • create conversation
      • Retrieve conversation
      • update conversation
      • delete conversation
      • Create items
      • list items
      • Retrieve item
      • Delete item
    • create completion
      POST
    • TTS text to speech
      POST
    • Embeddings
      POST
    • image generation
      POST
    • image editing
      POST
  • Store
    • List chat completions
      POST
    • Get chat completed
      POST
    • Deletion of chat completed
      POST
  • Claude
    • Anthropic native Completions enterprise commercial API
      POST
    • Anthropic native Messages API
      POST
    • Anthropic native Messages Token Count API
      POST
  • OAuth开放API
    • Introduction to Open OAuth API
    • User authorization page
      GET
    • Code display page
      GET
    • Apply for access_token
      POST
    • Read basic user information
      POST
    • Read user balance information
      POST
    • Charge user fees
      POST
    • Create a Stripe Checkout recharge order for the user
      POST
    • Create a Stripe Invoice recharge order for the user
      POST
    • Call other open APIs
      POST
    • Read user management token through OAuth Token
      POST
    • Update user management token through OAuth Token
      POST
  • other
    • search
      • Google Custom Search API
      • Google Search By Serper
    • Azure
      • Azure text-to-speech
      • Azure gets TTS voice list
  • Override rules
    • Create rules
    • Update rules
    • delete rule
    • Get rules
    • list rules
    • Batch enable/disable
    • Copy rules
    • test rules
    • Get statistics
    • Get restriction configuration
    • Check rule name
    • Batch delete
    • Export rules
    • Import rules
  • image generation
    • other
      • ND image generation API
    • Flux
      • Flux Schnell image generation
      • Flux Dev image generation
      • Flux Pro image generation
      • Flux Pro 1.1 image generation
      • Flux 1.1 Pro Ultura image generation
  • Storage service
    • File storage service
    • File upload
    • File information update
    • Delete files
    • User query (pagination)
    • User metadata query (by fileUinqueIds)
    • File download interface (Public file download)
    • File download interface (Private private file download)
    • Obtain public file metadata
  • API KEY management
    • Create new API Key
    • Modify API Key information
    • Query all API Keys of the user
    • Delete the specified API Key
    • Interface for querying user membership expiration date
    • User balance query interface
    • Query the current model magnification interface
  • Archive documents
    • Self-service invoicing system usage documentation
    • Telegram Bot usage documentation
    • Self-built Cloudflare Worker anti-generation tutorial
    • Claude Code forwarding service
    • CodeX forwarding service
    • Introduction to the new website
  • Model list
    GET
  1. Archive documents

Self-built Cloudflare Worker anti-generation tutorial

Introduction#

This article mainly explains how to build an API inversion service based on Cloudflare Worker to realize API original data recording + custom model rewriting function.
Occasionally, some users want to customize the model name to be compatible with some clients that behave strangely, and some users want to obtain the raw data of API interactions to troubleshoot errors. However, for the sake of compatibility and protecting customer privacy, we are not willing to directly add support for these functions on the server side. Therefore, we designed a small script based on CF Worker to simply implement these functions while taking into account security and privacy.
Effect display:
API model rewrite claude-3-haiku=>claude-3-5-haiku,claude-3.5-haiku-8080=>claude-3-5-sonnet:
image.png
API interaction raw data records:
image.png
#Configuration

Create Worker#

Go into your Cloudflare Dashboard
Click Worker & Pages => Overveiw => Create to create a new Worker
image.png
image.png
You can name it as you like, just click Create
image.png

Edit Worker code#

After successful creation, click Edit Code:
image.png
Clear the original code, then copy the entire code below, then click Deploy to save and update the deployment
image.png

Create and initialize D1 database#

Worker & Pages => D1 => Create button to create a new database
image.png
The name is arbitrary, just click Create after entering it.
image.png
Initialize the database and execute the table creation statement:
Copy the above SQL into the blue box and execute it
image.png
This is considered successful:
image.png

Configure Worker#

Bind D1 database#

Find the Worker you just created
image.png
Bind D1 database:
image.png
image.png
Fill in DB here for the variable name. For the database, select the one just initialized. Click Deploy to deploy.
image.png

Configure Worker environment variables#

By default, this Worker can forward the API at this time, but will not perform any actions.
You can set the Worker environment variables here
image.png
image.png
If logging needs to be enabled:
New environment variable: API_LOGGING
Set it to enabled
If you need to use the log download interface, you need to configure the API key:
Environment variable: API_SEC_KEY
Set to a private key known only to you
If you need model override functionality:
Set environment variable: API_MODEL_REWRITE
Format: model1=>model2,model3=>model4

Start request#

Assume your Worker address is:
wandering-poetry-3106.hash070.workers.dev
Then if you want to access OpenAI's Chat.Completions API interface, you can make a request to this interface https://wandering-poetry-3106.hash070.workers.dev/v1/chat/completions. If you want to access the Messages API interface, you can make a request to https://wandering-poetry-3106.hash070.workers.dev/v1/messages.
image.png
If you need to download logs:
You can open the following URL in the browser (note that the address and Key are replaced with your own in this format)
https://[your Worker address]/logs?key=[your API_SEC_KEY]&format=[export data format]

For example:
https://wandering-poetry-3106.hash070.workers.dev/logs?key=your-secret-key&format=csv
The key parameter in the URL should be filled in with the API_SEC_KEY variable set for you. format guides the data format, which can be a json or csv table.
If you need to clear data:
You can access this URL directly in your browser
https://[your Worker address]/clear-logs?key=[your API_SEC_KEY]
{"success":true,"message":{"en":"Logs cleared successfully","zh":"Logs cleared successfully"}}
Attached:
API interface description
Log export
Address:/logs
Method: GET
parameter:

key: API_SEC_KEY (required)
format: export format (optional, default csv)

csv: CSV format
json: JSON format
Example:
/logs?key=your-api-key
/logs?key=your-api-key&format=json
Log cleaning
Address:/clear-logs
Method: GET
parameter:

key: API_SEC_KEY (required)
Example:
/clear-logs?key=your-api-key
修改于 2025-10-15 08:07:31
上一页
Telegram Bot usage documentation
下一页
Claude Code forwarding service
Built with