x402 Quickstart

Use the Stock Trends API with standard x402

The Stock Trends API supports standard x402 V2 interoperability. If your client already speaks x402 V2, it can pay for Stock Trends premium endpoints with no Stock Trends-specific payment integration: no proprietary payment headers, no manual token transfer, and no submission of a pre-existing transaction hash.

x402 lets agents execute premium requests using permissionless per-request payment in USDC on Base — no subscription and no API key required.

The premium surface includes ST-IM forward-return intelligence, portfolio workflows, market regime analysis, breadth and leadership data, and structured decision endpoints.

Standard x402 V2 supported

Stock Trends accepts standard x402 V2 payments on Base. Conforming x402 V2 clients can handle the payment challenge, authorization, and retry without Stock Trends-specific payment headers or a manually supplied transaction hash.

x402 is an HTTP-native payment protocol for machine-to-machine payment. Stock Trends behaves like any other x402-enabled service:

request premium Stock Trends endpoint
        ↓
PAYMENT-REQUIRED
        ↓
x402 client authorizes payment
        ↓
PAYMENT-SIGNATURE
        ↓
Stock Trends response + PAYMENT-RESPONSE

Your x402 client performs the middle steps. You call the endpoint and read the result.

Parameter Value
Protocol x402 V2
Network Base
CAIP-2 network identifier eip155:8453
Settlement asset USDC
Challenge header PAYMENT-REQUIRED on the HTTP 402 response
Payment header PAYMENT-SIGNATURE on the client's retry
Settlement header PAYMENT-RESPONSE on the successful response
Pricing authority The live Stock Trends API. GET /v1/pricing/catalog is authoritative for current endpoint pricing.
x402 V2 live in production Base + USDC settlement No proprietary buyer integration

Examples

These use the official x402 V2 client libraries. Nothing in them is Stock Trends-specific except the URL. Check the current library documentation for the exact version you install; package APIs evolve independently of this portal.

TypeScript

npm install @x402/fetch @x402/evm viem
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);

const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [
    {
      network: "eip155:8453", // Base mainnet
      client: new ExactEvmScheme(account),
    },
  ],
});

const response = await fetchWithPayment(
  "https://api.stocktrends.com/v1/stim/latest?symbol_exchange=IBM-N",
  { method: "GET" },
);

console.log(await response.json());
console.log("settlement:", response.headers.get("PAYMENT-RESPONSE"));
  

Python

pip install "x402[requests]" eth-account
import os

from eth_account import Account
from x402 import x402ClientSync
from x402.http.clients import x402_requests
from x402.mechanisms.evm.exact import ExactEvmScheme

account = Account.from_key(os.environ["EVM_PRIVATE_KEY"])

client = x402ClientSync()
client.register("eip155:8453", ExactEvmScheme(account))

session = x402_requests(client)

response = session.get(
    "https://api.stocktrends.com/v1/stim/latest",
    params={"symbol_exchange": "IBM-N"},
)

print(response.json())
  

Inspecting the challenge with cURL

cURL cannot sign an x402 payment, but it is the quickest way to see the challenge for an endpoint before wiring up a client:

curl -i "https://api.stocktrends.com/v1/stim/latest?symbol_exchange=IBM-N"

The 402 response carries the standard PAYMENT-REQUIRED header and a JSON body containing accepted_payment_methods, pricing, payment_required, and a stocktrends_preview object. The preview describes the endpoint's purpose, required inputs, response shape, related endpoints, pricing rule, and cost — inspect it before paying.

Keep signing keys out of source control and out of client configuration files. Load them from the environment or a secrets manager, and set a maximum payment value in your x402 client so an unexpected price cannot be paid automatically.

Signal depth

Paid workflows use long-horizon Stock Trends signals

Premium ST-IM, screener, portfolio, regime, breadth, and leadership responses are built around Stock Trends classification semantics with historical records extending back to 1980 and 16M+ structured observations. They are market-intelligence workflows, not shallow market-data wrappers.

Treat paid responses as research provenance for probabilistic and agentic workflows. They are not investment advice, price targets, direct buy/sell commands, or guarantees of future performance.

Premium endpoint coverage

x402 payment support is active across premium endpoint families including:

  • ST-IM intelligence endpoints
  • Portfolio workflows
  • Decision workflows
  • Market regime intelligence
  • Leadership and breadth analysis
  • Agent screening workflows

The live pricing catalog remains authoritative for current premium coverage and endpoint cost behavior.

Pricing clarity: STC and USD cost

Stock Trends Credits (STC) are the API pricing unit.

Current billing presentation: 1 STC = $1.00 USD

The conversion below is illustrative, not a price list — it shows how an STC price maps to USD, using example amounts.

Example endpoint price Current USD cost
0.15 STC $0.15 USD
0.50 STC $0.50 USD
1.25 STC $1.25 USD

For the actual cost of a specific endpoint, call GET /v1/pricing/catalog. It and the payment-required response remain authoritative, and endpoint costs should not be hard-coded.

Recommended discovery workflow for AI agents

  1. Discover workflows: GET /v1/ai/tools
  2. Review indicator definitions: GET /v1/ai/context
  3. Inspect live pricing: GET /v1/pricing/catalog
  4. Estimate workflow cost: GET /v1/cost-estimate
  5. Execute a premium workflow

Recommended first premium endpoint

GET https://api.stocktrends.com/v1/agent/screener/top

Returns top-ranked instruments filtered by trend, exchange, RSI, and ST-IM intelligence.

Access: Subscription · x402 · MPP. Call GET /v1/pricing/catalog for this endpoint's current cost, or read it from the payment-required challenge before paying.

Optional agent identity headers

Independent of payment, these headers attribute requests to a persistent machine actor and improve usage tracking and agent ledger visibility. They are optional, and they are not part of the x402 flow.

X-StockTrends-Agent-Id: your-agent-id
X-StockTrends-Agent-Type: autonomous
X-StockTrends-Agent-Vendor: your-vendor
X-StockTrends-Request-Purpose: screening
  

GET /v1/pricing documents the current agent identity header set.

Declared payment metadata headers

The Stock Trends API also recognises a family of declared payment-metadata headers — X-StockTrends-Payment-Method, X-StockTrends-Payment-Network, X-StockTrends-Payment-Token, X-StockTrends-Payment-Reference, and X-StockTrends-Payment-Amount.

A conforming x402 V2 buyer does not need them. Do not add them to a standard x402 integration; the flow above is the normal path, and it is complete on its own.

Separate Stock Trends payment or session workflows may use additional metadata. For those workflows, consult the current MPP documentation and applicable API documentation rather than assuming the headers above carry over unchanged.

Next steps

  • Use MPP funded sessions for repeated workflows
  • Use the Stock Trends MCP server if you are working inside an MCP-compatible agent environment — note that the MCP adapter does not carry x402 payment
  • Use portfolio and decision workflows for actionable outputs
  • Combine regime, breadth, and leadership endpoints for market context