Skip to main content

API reference

Cortexhub​

Construct the client with either an agent API key or a programmatic MCP OAuth credential.

import cortexhub

cx = cortexhub.init("cxh_key_...") # alias for Cortexhub(api_key=...)
# or
from cortexhub import Cortexhub
cx = Cortexhub(api_key="cxh_key_...")
cx = Cortexhub(client_id="...", client_secret="...")

cortexhub.init(api_key=None, **kwargs) is a thin alias for Cortexhub(...). It accepts the key positionally (cortexhub.init("cxh_key_...")); the Cortexhub(...) constructor is keyword-only (use Cortexhub(api_key="cxh_key_..."), not Cortexhub("cxh_key_...")).

If both credential paths are configured, the API-key path is used.

Constructor​

ArgumentDescription
api_keyAgent API key beginning with cxh_key_
client_id, client_secretProgrammatic MCP OAuth credentials
token_urlOverride the OAuth token endpoint

Methods and properties​

MemberDescription
session(...)Creates one conversation/run handle
mcp(...)Shortcut for session(...).mcp
fetch_token(...)Gets an OAuth token; OAuth path only
aiAI gateway URL and key; API-key path only
llmOpenAI client convenience property; API-key path only. Use session.llm when attribution and grouping are required.
modeActive credential path

session requires agent for MCP connections. mcp_session_id is the caller-owned conversation or run ID. end_user_subject is required for API-key requests. end_user_display_hint is optional presentation text.

McpKeySession​

Fields include api_key, agent, mcp_session_id, end_user_subject, end_user_display_hint, mcp, session_id, and llm.

decide(approval_id, decision, note=None) relays an end user's approve/deny for a governed tool call that parked for consent. decision is "approve" or "deny"; note is optional. Authenticated by this session's org key, agent, and end_user_subject; the decision is recorded as that end user's consent. See Approvals.

McpOAuthSession​

Fields include access_token, agent, mcp_session_id, conversation_title, last_user_message, and mcp.

SessionMcp​

SessionMcp exposes url and headers for your MCP transport. SessionMcp.open() opens the Streamable HTTP transport and yields read/write streams for mcp.ClientSession. It requires the mcp extra.

Configuration​

VariableDefault
CORTEXHUB_API_KEYnone
CORTEXHUB_URLhttps://mcp.cortexhub.ai
CORTEXHUB_ROUTER_URLhttps://api.cortexhub.ai/v1
CORTEXHUB_CLIENT_IDnone
CORTEXHUB_CLIENT_SECRETnone

See Errors.