Skip to content

Instantly share code, notes, and snippets.

@jongan69
Created June 8, 2025 08:48
Show Gist options
  • Save jongan69/1d2a8f5d8885612976c2bbdb33e0069b to your computer and use it in GitHub Desktop.
Save jongan69/1d2a8f5d8885612976c2bbdb33e0069b to your computer and use it in GitHub Desktop.
goose api wrapper
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import subprocess
app = FastAPI()
class GooseInput(BaseModel):
instructions: str
session_name: str = "api-session"
@app.post("/run-goose/")
def run_goose(input: GooseInput):
try:
# Save instructions to a file
instruction_file = "/tmp/goose_input.txt"
with open(instruction_file, "w") as f:
f.write(input.instructions)
# Run goose with instructions
result = subprocess.run(
["goose", "run", "--name", input.session_name, "-i", instruction_file],
capture_output=True,
text=True
)
if result.returncode != 0:
raise HTTPException(status_code=500, detail=result.stderr)
return {
"stdout": result.stdout,
"stderr": result.stderr,
"returncode": result.returncode
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment