Custom Python Agents + Govyn — Govern Any Python Agent

Custom Python agents give you full flexibility, but that also means full responsibility for cost control and security. Whether you're using the OpenAI SDK, httpx, or raw requests, there's no centralized way to enforce budgets, restrict models, or audit API calls — until you add a governance proxy.

How it works

Python
Your agents
HTTPS
Govyn Proxy
Policy · Budget · Logs
API
Any Provider API
LLM provider

Step-by-step setup

1

Start the Govyn proxy

bash
npx govyn start --config govyn.yaml
2

Point the OpenAI SDK at Govyn

python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:4111/v1",
    api_key="gvn_agent_python_01"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}]
)
3

Or use httpx / requests directly

python
import httpx

response = httpx.post(
    "http://localhost:4111/v1/chat/completions",
    headers={"Authorization": "Bearer gvn_agent_python_01"},
    json={
        "model": "gpt-4o",
        "messages": [{"role": "user", "content": "Hello"}]
    }
)

Example policy

Define governance rules for your Python agents in a simple YAML file.

govyn.yaml
agents:
  python_01:
    budget:
      daily: $5.00
      monthly: $100.00
    models:
      allow: [gpt-4o, gpt-4o-mini, claude-sonnet-4-20250514]
    providers:
      allow: [openai, anthropic]
    rate_limit:
      requests_per_minute: 30
    logging:
      replay: true

Why use Govyn with Python?

Works with any Python HTTP client
Compatible with OpenAI and Anthropic SDKs
Multi-provider support from a single proxy
Budget caps and rate limiting
Full request/response logging
No framework lock-in

Get started in 5 minutes

Add governance to your Python agents with a single config change. No code rewrites.

Read the docs

Frequently asked questions

Do I need to use a specific Python framework?
No. Govyn works at the HTTP level, so it's compatible with any Python HTTP client — the OpenAI SDK, Anthropic SDK, httpx, requests, aiohttp, or even urllib. If your code makes HTTP calls to an LLM API, Govyn can govern it.
Can I route to multiple providers through one proxy?
Yes. Govyn supports smart routing — you can send requests to OpenAI, Anthropic, and other providers through a single proxy endpoint. Configure routing rules in your YAML policy to direct traffic based on model name or agent key.
How do I migrate my existing Python agent to use Govyn?
Just change the base URL and API key in your HTTP client configuration. If you're using the OpenAI SDK, that's two lines. If you're using raw HTTP calls, swap the hostname. No other code changes are needed.

Related integrations

Explore more