Skip to main content

Install

pip install grantex-openai-agents
OpenAI Agents SDK is a peer dependency:
pip install openai-agents

Quick Start

from grantex_openai_agents import create_grantex_tool

tool = create_grantex_tool(
    name="read_calendar",
    description="Read upcoming calendar events",
    grant_token=grant_token,       # JWT from Grantex authorization flow
    required_scope="calendar:read",
    func=get_calendar_events,
)

# Use with any OpenAI Agents SDK agent
from agents import Agent
agent = Agent(name="assistant", tools=[tool])
If the grant token doesn’t include the required scope, create_grantex_tool raises a PermissionError immediately — the tool is never created.

API Reference

create_grantex_tool()

Creates an OpenAI Agents SDK FunctionTool with offline scope enforcement.
ParameterTypeDescription
namestrTool name
descriptionstrTool description
grant_tokenstrJWT grant token from Grantex
required_scopestrScope that must be present in the token
funcCallable[..., str]The function to wrap

get_tool_scopes(grant_token)

Returns the scopes embedded in a grant token (offline, no network call).

decode_jwt_payload(token)

Decodes the payload of a JWT without verifying the signature. Useful for inspecting token claims.

Requirements

  • Python 3.9+
  • grantex >= 0.1.0
  • openai-agents >= 0.0.3 (peer dependency)