API¶
Request Example¶
Curl example: curl -H 'Authorization: Bearer ${secret}' http://${controller-api}/configs?force=true -d '{"path": "", "payload": ""}' -X PUT
This request includes the header 'Authorization: Bearer ${secret}', where:
${secret}is the API key set in the configuration file api${controller-api}is the API listening address set in the configuration file api?force=trueis a parameter that needs to be included in certain requests'{"path": "", "payload": ""}'is the data for the resource to be updated
Note
If you need to pass a path, please note that if the path is not in the mihomo working directory, please manually set the SAFE_PATHS environment variable to add it to the safe path. The syntax of this environment variable is the same as the PATH environment variable parsing rules of this operating system (i.e., semicolon-separated in Windows and colon-separated in other systems).
Logs¶
/logs¶
Retrieve real-time logs
- Request method:
GET/WS - Optional parameter:
?level=log_level, wherelog_levelcan beinfo,warning,error,debug - Optional parameter:
?format=structured, when present outputs structured logs (withtime,level,message,fieldsfields) - Response fields (standard mode, one JSON per line):
type: log level —info/warning/error/debugpayload: log message content
- Response fields (structured mode
?format=structured):time: time string inHH:MM:SSformatlevel: log levelmessage: log message contentfields: array of additional fields
Traffic Information¶
/traffic¶
Retrieve real-time traffic; up/down are in bytes/s, upTotal/downTotal are in bytes
- Request method:
GET/WS - Response fields (pushed once per second):
up: current upload rate (bytes/s)down: current download rate (bytes/s)upTotal: cumulative uploaded bytesdownTotal: cumulative downloaded bytes
Memory Information¶
/memory¶
Retrieve real-time memory usage, measured in bytes
- Request method:
GET/WS - Response fields (pushed once per second):
inuse: current memory in use (bytes)oslimit: OS memory limit (bytes, always0)
Version Information¶
/version¶
Retrieve the Clash version
- Request method:
GET - Response fields:
meta: whether this is a Meta build (true/false)version: version string
Cache¶
/cache/fakeip/flush¶
Clear the fake IP cache
- Request method:
POST - Response: none (HTTP 204)
/cache/dns/flush¶
Clear the DNS cache
- Request method:
POST - Response: none (HTTP 204)
Running Configuration¶
/configs¶
Retrieve basic configuration
- Request method:
GET - Response fields: JSON object of the current running configuration, including
port,socks-port,mixed-port,mode,log-level,allow-lan,ipv6,tun, and other fields
Reload basic configuration
- Request method:
PUT - Parameter:
?force=true - Response: none (HTTP 204)
Update basic configuration
- Request method:
PATCH - Data:
'{"mixed-port": 7890}' - Response: none (HTTP 204)
/configs/geo¶
Update the GEO database
- Request method:
POST - Data:
'{"path": "", "payload": ""}' - Response: none (HTTP 204)
/restart¶
Restart the kernel
- Request method:
POST - Data:
'{"path": "", "payload": ""}' - Response: none (HTTP 204)
Updates¶
/upgrade¶
Update the kernel
- Request method:
POST - Optional parameters:
?channel=xxxspecifies the update channel,?force=trueforces the update - Data:
'{"path": "", "payload": ""}' - Response fields:
status: fixed value"ok"
/upgrade/ui¶
Update the panel; external-ui must be set
- Request method:
POST - Response fields:
status: fixed value"ok"
/upgrade/geo¶
Update the GEO database
- Request method:
POST - Data:
'{"path": "", "payload": ""}' - Response: none (HTTP 204)
Policy Groups¶
/group¶
Retrieve policy group information
- Request method:
GET - Response fields:
proxies: array of policy group objects, each in the same format as/proxies/proxies_name
/group/group_name¶
Retrieve specific policy group information
- Request method:
GET - Response fields: policy group object, same format as
/proxies/proxies_name
/group/group_name/delay¶
Test the nodes/strategy groups within the specified strategy group, return new latency information, and clear the fixed selection of the automatic strategy group
- Request method:
GET - Parameter:
?url=xxx&timeout=5000 - Optional parameter:
?expected=xxx, the expected HTTP response status code, supports ranges (e.g.200/204,200-299) - Response fields: JSON object mapping node names to their latency in milliseconds (
uint16), e.g.{"Node A": 120, "Node B": 350}
Proxies¶
/proxies¶
Retrieve proxy information
- Request method:
GET - Response fields:
proxies: object keyed by proxy/group name; every entry shares these common fields:name: proxy or group nametype: type (e.g.Shadowsocks,VMess,DIRECT,Selector,URLTest,Fallback,LoadBalance, etc.)udp: whether UDP is supporteduot: whether UDP over TCP is supportedxudp: whether XUDP is supportedtfo: whether TCP Fast Open is enabledmptcp: whether MPTCP is enabledsmux: whether stream multiplexing is enabledalive: whether the proxy is currently alivehistory: array of delay history entries, each withtimeanddelay(ms)extra: extra delay histories grouped by test URLinterface: bound network interface namerouting-mark: routing mark valueprovider-name: name of the proxy provider this proxy belongs todialer-proxy: underlying dialer proxy name
- Policy groups (
Selector,URLTest,Fallback,LoadBalance) additionally include:now: currently selected node name (absent forLoadBalance)all: array of all node/group names in the grouptestUrl: health check URLhidden: whether the group is hidden in the dashboardicon: icon URLemptyFallback: fallback node name used when all members are unavailableexpectedStatus: expected HTTP response status code for health checks (absent forSelector)fixed: currently pinned node name (onlyURLTestandFallback)
/proxies/proxies_name¶
Retrieve specific proxy information
- Request method:
GET - Response fields: proxy or group object, same fields as a single entry under
/proxies(regular proxies have only the common fields; policy groups additionally includenow,all, etc.)
Select a specific proxy
- Request method:
PUT - Data:
'{"name":"Japan"}' - Response: none (HTTP 204)
Clear the fixed selection of the proxy/policy group (except for the Selector type)
- Request method:
DELETE - Response: none (HTTP 204)
/proxies/proxies_name/delay¶
Test a specified proxy and return new delay information
- Request method:
GET - Parameter:
?url=xxx&timeout=5000 - Optional parameter:
?expected=xxx, the expected HTTP response status code, supports ranges (e.g.200/204,200-299) - Response fields:
delay: measured latency in milliseconds (uint16)
Proxy Sets¶
/providers/proxies¶
Retrieve all information for all proxy sets
- Request method:
GET - Response fields:
providers: object keyed by provider name, each containing provider metadata and its proxy list
/providers/proxies/providers_name¶
Retrieve information for a specific proxy set
- Request method:
GET - Response fields: proxy provider object including configuration metadata and a
proxieslist
Update the proxy set
- Request method:
PUT - Response: none (HTTP 204)
/providers/proxies/providers_name/healthcheck¶
Trigger a health check for a specific proxy set
- Request method:
GET - Response: none (HTTP 204)
/providers/proxies/providers_name/proxies_name¶
Retrieve information for a specified proxy within the proxy set
- Request method:
GET - Response fields: proxy object, same fields as
/proxies/proxies_name
/providers/proxies/providers_name/proxies_name/healthcheck¶
Test a specified proxy within the proxy set and return new delay information
- Request method:
GET - Parameter:
?url=xxx&timeout=5000 - Response fields:
delay: measured latency in milliseconds (uint16)
Rules¶
/rules¶
Retrieve rule information
- Request method:
GET - Response fields:
rules: array of rule objects, each containing:index: rule index (0-based)type: rule type (e.g.DOMAIN,IP-CIDR,GEOIP, etc.)payload: rule match contentproxy: target proxy or policy group namesize: number of entries in the rule set (only valid forGEOIP/GEOSITE,-1otherwise)extra(optional, when present includes):disabled: whether the rule is disabledhitCount: number of times the rule was matchedhitAt: timestamp of the last matchmissCount: number of times the rule was not matchedmissAt: timestamp of the last miss
/rules/disable¶
Disable rules, where the key is the rule index and the value is whether to disable the rule. This is a temporary operation and is reset after a restart.
- Request method:
PATCH - Data:
'{"0": false,"1": true}' - Response: none (HTTP 204)
Rule Sets¶
/providers/rules¶
Retrieve all information for all rule sets
- Request method:
GET - Response fields:
providers: object keyed by rule provider name
/providers/rules/providers_name¶
Update the rule set
- Request method:
PUT - Response: none (HTTP 204)
Connections¶
/connections¶
Retrieve connection information
- Request method:
GET/WS - Optional parameter:
?interval=milliseconds, wheremillisecondsis the refresh interval, default value is 1000 milliseconds - Response fields:
downloadTotal: cumulative downloaded bytesuploadTotal: cumulative uploaded bytesmemory: current memory usage (bytes)connections: array of active connection objects, each containing:id: unique connection IDmetadata: connection metadata (source/destination address, protocol, process name, etc.)upload: bytes uploaded on this connectiondownload: bytes downloaded on this connectionstart: connection start timechains: proxy chain arrayproviderChains: provider proxy chain arrayrule: matched rule typerulePayload: matched rule content
Close all connections
- Request method:
DELETE - Response: none (HTTP 204)
/connections/:id¶
Close a specific connection
- Request method:
DELETE - Response: none (HTTP 204)
Domain Query¶
/dns/query¶
Retrieve DNS query data for a specified name and type
- Request method:
GET - Parameter:
?name=example.com&type=A - Response fields:
Status: DNS response code (Rcode)Question: array of query questionsTC: whether the response is truncatedRD: recursion desired flagRA: recursion available flagAD: authenticated data flagCD: checking disabled flagAnswer(optional): array of answer records, each withname,type,TTL,dataAuthority(optional): array of authority records, same format asAnswerAdditional(optional): array of additional records, same format asAnswer
Storage¶
/storage/key¶
Retrieve the storage value for the specified key, returns null if it does not exist
- Request method:
GET - Response fields: any valid JSON value that was stored, or
nullif the key does not exist
Write the storage value for the specified key; the data must be valid JSON, maximum 1MB
- Request method:
PUT - Data:
'{"foo": "bar"}' - Response: none (HTTP 204)
Delete the storage value for the specified key
- Request method:
DELETE - Response: none (HTTP 204)
DEBUG¶
/debug requires the kernel to be started with the log level set to debug.
/debug/gc¶
Perform active garbage collection
- Request method:
PUT - Response: none (HTTP 204)
/debug/pprof¶
Open in a browser http://${controller-api}/debug/pprof to view raw DEBUG information, where:
allocsindicates memory allocation for each function call, including the size of memory allocated on the stack and heap, as well as the number of allocations. This report is primarily to help identify memory leaks and frequent memory requests in the code.- The
heapreport provides detailed information about memory usage on the heap, including the size, number, and address of allocated memory blocks, sorted by size. This report is mainly to locate areas of excessive memory usage; we can check object sizes in the heap report to find areas of high memory consumption.
Install Graphviz to view graphical debug information.¶
View Graphical Heap Report¶
View Graphical Allocs Report¶
Submit Output Report¶
Access http://${controller-api}/debug/pprof/heap?raw=true in a browser to download this file, and upload it to issues to report any problems you encounter.