How to Pull US Trade Data in Codex for Market Research

Codex excels at autonomous research tasks, but it can’t reach trade databases on its own. When you need it to size a market, validate an import trend, or build fixtures around real trade volumes, you’d normally export CSVs from the Census Bureau yourself. AgentPatch adds a Trade Data tool that lets Codex query US import/export data directly.

Why This Matters

Market research for physical goods almost always comes back to trade data. If you want to know how large the US market is for a specific product category, import values are one of the most reliable signals. But the Census Bureau’s International Trade portal is built for humans clicking through dropdowns, not for AI agents running autonomously.

The Trade Data tool translates that into a single structured call. Codex specifies the direction (imports or exports), commodity granularity (HS2 for broad categories, HS4 for product groups, HS6 for specific items), and a time period in YYYY-MM format. It can optionally filter by country code or commodity code. Results come back sorted by value, with commodity descriptions, country names, monthly values, and year-to-date totals. Each call costs 75 credits.

Setup

Add AgentPatch to ~/.codex/config.toml:

[mcp_servers.agentpatch]
url = "https://agentpatch.ai/mcp"
bearer_token_env_var = "AGENTPATCH_API_KEY"

Then set your API key:

export AGENTPATCH_API_KEY=your_api_key

Replace your_api_key with your actual key from the AgentPatch dashboard. Codex discovers all AgentPatch tools automatically on next start.

Example

You’re building a market sizing tool for consumer goods companies and need Codex to validate it against real data. You tell it:

“Research the US import market for footwear. Pull HS4-level import data for December 2025 to see the major subcategories, then drill into the top one at HS6 level to see which countries dominate. Summarize the findings and create seed data for the market-sizing module.”

Codex runs the research autonomously:

Fetching HS4-level US footwear imports for 2025-12...
Direction: imports, commodity level: HS4, time: 2025-12
Filtering to HS chapter 64 (footwear)

Top HS4 subcategories by monthly value:
1. 6404 - Footwear with textile uppers:    $1.87B
2. 6403 - Footwear with leather uppers:    $1.42B
3. 6402 - Rubber/plastics footwear:        $1.15B

Drilling into 6404 at HS6 level...

Top source countries for textile-upper footwear:
1. China (5700):    $892M monthly,   $10.4B YTD
2. Vietnam:         $624M monthly,   $7.2B YTD
3. Indonesia:       $198M monthly,   $2.3B YTD

Writing seed data to fixtures/footwear-market.json with the schema
matching MarketSegment interface. Total US footwear imports for Dec 2025
exceeded $5.1B across all subcategories.

Codex sized the market, identified the dominant subcategories and source countries, and produced structured seed data — all without you opening a browser or downloading a CSV.

Wrapping Up

Connecting AgentPatch to Codex gives it direct access to US trade data from the Census Bureau during any autonomous session. Combine it with fred-data for macro context or Google News for trade policy signals. The same connection unlocks every other tool on the marketplace — no additional setup per tool. See what’s available at agentpatch.ai.