22
33This document describes the REST API for the Buttercup Program Model service, which provides code analysis and harness discovery capabilities for the Buttercup CRS system.
44
5- ## Overview
6-
7- The Program Model REST API replaces direct execution of ` codequery ` and ` cscope ` tools, providing better isolation between components. The API exposes program analysis functionality through HTTP endpoints, allowing the patcher and seed-gen components to interact with the program model service remotely.
8-
95## Base URL
106
117The default base URL for the API is ` http://localhost:8000 ` . This can be configured using the ` PROGRAM_MODEL_API_URL ` environment variable.
@@ -16,15 +12,15 @@ To start the API server:
1612
1713``` bash
1814# Using the CLI command
19- buttercup-program-model-api --host 0.0.0.0 --port 8000
15+ buttercup-program-model-api --host localhost --port 8000
2016
2117# Or using uvicorn directly
22- uvicorn buttercup.program_model.api.server:app --host 0.0.0.0 --port 8000
18+ uvicorn buttercup.program_model.api.server:app --host localhost --port 8000
2319```
2420
2521### CLI Options
2622
27- - ` --host ` : Host to bind the server to (default: 0 .0.0.0 )
23+ - ` --host ` : Host to bind the server to (default: 127 .0.0.1 )
2824- ` --port ` : Port to bind the server to (default: 8000)
2925- ` --workers ` : Number of worker processes (default: 1)
3026- ` --log-level ` : Log level (debug, info, warning, error, critical)
@@ -43,6 +39,7 @@ Currently, the API does not require authentication. In production deployments, c
4339Returns the health status of the API server.
4440
4541** Response:**
42+
4643``` json
4744{
4845 "status" : " healthy"
@@ -56,9 +53,11 @@ Returns the health status of the API server.
5653Initialize a CodeQuery instance for a task.
5754
5855** Parameters:**
56+
5957- ` task_id ` (path): The task ID to initialize
6058
6159** Request Body:**
60+
6261``` json
6362{
6463 "task_id" : " string" ,
@@ -67,6 +66,7 @@ Initialize a CodeQuery instance for a task.
6766```
6867
6968** Response:**
69+
7070``` json
7171{
7272 "task_id" : " string" ,
@@ -80,9 +80,11 @@ Initialize a CodeQuery instance for a task.
8080Clean up a task and its associated resources.
8181
8282** Parameters:**
83+
8384- ` task_id ` (path): The task ID to cleanup
8485
8586** Response:**
87+
8688``` json
8789{
8890 "status" : " cleaned_up" ,
@@ -97,6 +99,7 @@ Clean up a task and its associated resources.
9799Search for functions in the codebase.
98100
99101** Parameters:**
102+
100103- ` task_id ` (path): The task ID
101104- ` function_name ` (query): Function name to search for
102105- ` file_path ` (query, optional): File path to search within
@@ -105,6 +108,7 @@ Search for functions in the codebase.
105108- ` fuzzy_threshold ` (query, optional): Fuzzy matching threshold 0-100 (default: 80)
106109
107110** Response:**
111+
108112``` json
109113{
110114 "functions" : [
@@ -129,11 +133,13 @@ Search for functions in the codebase.
129133Get callers of a function.
130134
131135** Parameters:**
136+
132137- ` task_id ` (path): The task ID
133138- ` function_name ` (path): The function name
134139- ` file_path ` (query, optional): File path of the function
135140
136141** Response:**
142+
137143``` json
138144{
139145 "functions" : [... ],
@@ -146,12 +152,14 @@ Get callers of a function.
146152Get callees of a function.
147153
148154** Parameters:**
155+
149156- ` task_id ` (path): The task ID
150157- ` function_name ` (path): The function name
151158- ` file_path ` (query, optional): File path of the function
152159- ` line_number ` (query, optional): Line number of the function
153160
154161** Response:**
162+
155163``` json
156164{
157165 "functions" : [... ],
@@ -166,6 +174,7 @@ Get callees of a function.
166174Search for types in the codebase.
167175
168176** Parameters:**
177+
169178- ` task_id ` (path): The task ID
170179- ` type_name ` (query): Type name to search for
171180- ` file_path ` (query, optional): File path to search within
@@ -174,6 +183,7 @@ Search for types in the codebase.
174183- ` fuzzy_threshold ` (query, optional): Fuzzy matching threshold 0-100 (default: 80)
175184
176185** Response:**
186+
177187``` json
178188{
179189 "types" : [
@@ -194,11 +204,13 @@ Search for types in the codebase.
194204Get usage locations of a type.
195205
196206** Parameters:**
207+
197208- ` task_id ` (path): The task ID
198209- ` type_name ` (path): The type name
199210- ` file_path ` (query, optional): File path of the type
200211
201212** Response:**
213+
202214``` json
203215[
204216 {
@@ -216,9 +228,11 @@ Get usage locations of a type.
216228Find libfuzzer harnesses in the codebase.
217229
218230** Parameters:**
231+
219232- ` task_id ` (path): The task ID
220233
221234** Response:**
235+
222236``` json
223237{
224238 "harnesses" : [" string" ],
@@ -231,9 +245,11 @@ Find libfuzzer harnesses in the codebase.
231245Find jazzer harnesses in the codebase.
232246
233247** Parameters:**
248+
234249- ` task_id ` (path): The task ID
235250
236251** Response:**
252+
237253``` json
238254{
239255 "harnesses" : [" string" ],
@@ -246,10 +262,12 @@ Find jazzer harnesses in the codebase.
246262Get source code for a specific harness.
247263
248264** Parameters:**
265+
249266- ` task_id ` (path): The task ID
250267- ` harness_name ` (path): The harness name
251268
252269** Response:**
270+
253271``` json
254272{
255273 "file_path" : " string" ,
@@ -268,6 +286,7 @@ The API uses standard HTTP status codes:
268286- ` 500 ` : Internal server error
269287
270288Error responses follow this format:
289+
271290``` json
272291{
273292 "error" : " string" ,
@@ -335,17 +354,22 @@ The program-model service can be deployed as a Docker container. Ensure the API
335354
336355## Migration Guide
337356
357+ The previous version of Buttercup required components (e.g., ` patcher ` and ` seed-gen ` ) to install ` codequery ` and ` cscope ` dependencies.
358+
359+ This REST API removes those requirements.
360+
338361### From Direct CodeQuery Usage
339362
3403631 . ** Remove Dependencies** : Remove ` codequery ` and ` cscope ` from Dockerfiles
3413642 . ** Update Imports** : Change imports from ` buttercup.program_model.codequery ` to ` buttercup.program_model.rest_client `
3423653 . ** Update Instantiation** : Replace ` CodeQueryPersistent ` with ` CodeQueryPersistentRest `
343- 4 . ** Start API Server** : Ensure the program-model API server is running
366+ 4 . ** Start API Server** : Ensure the ` program-model ` API server is running
3443675 . ** Configuration** : Set ` PROGRAM_MODEL_API_URL ` if using a non-default server location
345368
346369### Example Migration
347370
348371** Before:**
372+
349373``` python
350374from buttercup.program_model.codequery import CodeQueryPersistent
351375
@@ -354,6 +378,7 @@ functions = codequery.get_functions("function_name")
354378```
355379
356380** After:**
381+
357382``` python
358383from buttercup.program_model.rest_client import CodeQueryPersistentRest
359384
@@ -385,10 +410,10 @@ Enable debug logging to troubleshoot issues:
385410buttercup-program-model-api --log-level debug
386411```
387412
388- ### Health Check
413+ ### Check Health
389414
390415Use the health endpoint to verify the server is running:
391416
392417``` bash
393418curl http://localhost:8000/health
394- ```
419+ ```
0 commit comments