US 30-Year Treasury Yield API: US_30Y as JSON

US 30-Year Treasury Yield API: US_30Y as JSON

You need the US long bond yield in your own code without scraping, spreadsheets, or delayed files. By the end of this article, you will request the US 30‑year Treasury yield (symbol: US_30Y) as JSON from a production REST API, parse it in Python, understand the units and dates, and know how to handle business days, holidays, and caching when you ship to prod.

What “US_30Y” is and why a single‑tenor endpoint matters

US_30Y is the 30‑year point on the US Treasury yield curve—often called the “long bond.” If you’re pricing mortgages, valuing long‑duration liabilities, running macro dashboards, or stress‑testing with scenario shocks, you often need just this one tenor at high frequency. A single‑tenor endpoint keeps your data pull simple and fast when the full curve is unnecessary.

Bonds‑API exposes US_30Y via a “latest” endpoint that returns the most recent value. It provides structured JSON and is authenticated with an API key passed as a query parameter. For full‑curve needs (e.g., 3M through 30Y), you can switch to the curve endpoint; more on that below.

If you’re new to the API, start from the homepage at bonds-api.com and the documentation at bonds-api.com/docs. You can also explore with the hosted MCP environment here: MCP.

Endpoint and authentication

To fetch the latest US 30‑year Treasury yield, call the “latest” endpoint with:

  • Method: GET
  • URL: https://bonds-api.com/api/v1/latest
  • Query parameters:
    • countries=US
    • maturities=30Y
    • api_key=YOUR_API_KEY

Important details:

  • Authentication: pass api_key as a query parameter (not a Bearer header).
  • Tenor selection: maturities is 30Y for the long bond.
  • Country: countries=US targets Treasuries.

Plans start at a developer‑friendly tier, and there’s a trial if you need to validate the fit in your stack. You can create an account in minutes and obtain your key:

For an overview and links to documentation, the product homepage is also a good launch point: bonds-api.com.

cURL: latest US_30Y in one request

The following is the exact request you can copy and paste to retrieve the latest US 30‑year yield (US_30Y). Replace YOUR_API_KEY with your token after you register.

curl "https://bonds-api.com/api/v1/latest?countries=US&maturities=30Y&api_key=YOUR_API_KEY"

Notes when you run this:

  • You should get JSON back. Keep the response for parsing and logging.
  • If you are building a UI, do not poll aggressively; cache the last successful response to minimize request volume.
  • If the market is closed (e.g., weekends or holidays), the latest value typically reflects the last available trading day; plan your downstream logic accordingly.

Python example: request and parse US_30Y

Below is a concise Python example that calls the same endpoint, checks for a successful HTTP response, and prints the raw JSON. This keeps field handling flexible across versions. Plug it into your pipeline or a scheduled job.

import os
import sys
import time
import json
import urllib.parse
import urllib.request

API_BASE = "https://bonds-api.com/api/v1/latest"
API_KEY = os.environ.get("BONDS_API_KEY", "YOUR_API_KEY")  # set BONDS_API_KEY in your env for production

params = {
    "countries": "US",
    "maturities": "30Y",
    "api_key": API_KEY
}
url = f"{API_BASE}?{urllib.parse.urlencode(params)}"

req = urllib.request.Request(url, method="GET")

try:
    with urllib.request.urlopen(req, timeout=10) as resp:
        status = resp.getcode()
        body = resp.read().decode("utf-8")
        if status != 200:
            sys.stderr.write(f"Non-200 HTTP status: {status}\n")
            sys.stderr.write(body + "\n")
            sys.exit(1)
        data = json.loads(body)
        # Print the JSON exactly as returned so you can inspect available fields
        print(json.dumps(data, indent=2))
except Exception as e:
    # Backoff and retry pattern for transient network or upstream hiccups
    sys.stderr.write(f"Request failed: {e}\n")
    time.sleep(2)
    sys.exit(2)

Why read the JSON dynamically? The “latest” and “curve” endpoints can differ in shape, and Bonds‑API can add fields over time. Logging the raw response ensures your observability is concrete and schema drift is manageable.

Official JSON sample and how to read it

The following JSON block comes from the official US curve example for a specific market date. It includes the 30‑year point among others. This sample illustrates how yields are represented and how to read dates in responses. The request in the previous section is for the single‑tenor US_30Y (latest); when you need multiple maturities at once, use the curve endpoint as indicated in the docs.

{
  "success": true,
  "data": {
    "country": "US",
    "date": "2026-04-14",
    "curve": [
      {"maturity": "3M", "yield": 4.30},
      {"maturity": "30Y", "yield": 4.55}
    ],
    "spread_2y_10y": 45.0,
    "inverted": false
  }
}

How to interpret the values:

  • Units: Numbers such as 4.55 represent percent yields (e.g., 4.55%). They are not basis points. Convert to decimal form in calculations (0.0455) if your pricing or discounting library expects decimals.
  • Date: The example is tied to a clear market date. In many curve responses, you’ll see a date field that fixes the snapshot to a trading day. Treat it as the canonical as‑of date for analysis, caching, partitioning in storage, and charting.
  • Multiple maturities: The example shows other points (such as 2Y, 5Y, 10Y) alongside 30Y for the same date. Use these together to build a curve or compute spreads.

Note that the JSON structure of the curve endpoint can differ from the latest single‑tenor endpoint you called above. When you switch from one to the other, inspect the JSON and adapt your parsing code accordingly (e.g., field paths, timestamps present or absent). If you are building a common parsing layer, base it on actual keys you receive at runtime rather than relying on fixed assumptions.

From single tenor to full curve

If your application needs only the US_30Y, the “latest” call is ideal: minimal response size and lower overhead. When you need 3M–30Y together (for term structure modeling, interpolation, or fitting), use the curve endpoint mentioned in the documentation. The official curve sample above illustrates how multiple maturities appear in one payload, including the 30‑year point.

Practical development notes:

  • Do not issue multiple single‑tenor requests in a loop to mimic a curve; request the curve once. It reduces latency and keeps your curve internally consistent as‑of a single market time.
  • If you only plot or alert on long‑end moves, stick with US_30Y to keep costs and parsing simple, and fall back to /curve only when the context of belly/front moves matters.
  • When computing long‑end spreads (e.g., 30s–10s), fetch both tenors from the curve snapshot; differences computed from two separate “latest” requests might cross ticks if markets move between calls.

Operational realities: updates, business days, holidays, and caching

Market data has cadence and downtime. These notes will save you integration time and noisy alerts:

  • Business days vs. weekends/holidays: Treasury markets observe US holidays. On such days (and weekends), do not expect a fresh intraday tick. “Latest” will typically give you the most recent available market day. In job schedulers, guard against false alarms by checking whether the calendar day is a known market holiday.
  • Update frequency: The “latest” endpoint is designed for the freshest snapshot available from Bonds‑API at query time. If you poll for dashboards, implement a reasonable interval (e.g., minutes, not seconds) unless you specifically need finer granularity. Cache the last good payload and re‑use it for downstream renders to keep your UI responsive regardless of transient network issues.
  • Caching and ETags: Even if you do not have HTTP cache negotiation built in, keep a simple in‑process cache keyed by as‑of date (and maturity) to prevent downstream recomputation. In functions or lambdas, consider short TTLs so warm containers share the same response for a minute or two.
  • Backoff and retries: On network timeouts or HTTP non‑200s, use exponential backoff. Avoid tight retry loops that could push you over request budgets.
  • Missing or null values: If a field is missing for a given tenor on a given day, treat it as unavailable and propagate an explicit “no data” state to your UI rather than coercing to zero. Prefer skipping that tenor in calculations over substituting a stale value without labeling it.
  • Error handling: Some APIs include top‑level flags (e.g., a “success” boolean) in addition to HTTP statuses. If present in your response, treat a false value as non‑OK. If your response has no such flag, rely on HTTP status codes and validate that the keys you expect for US_30Y are present before using the numbers.

Reading units, dates, and time zones safely

Units: The curve example shows yields as percent (e.g., 4.55 means 4.55%). In your math layer:

  • Display layer: Keep percent with two decimals for end users (4.55%).
  • Math layer: Convert percent to decimal (divide by 100) for pricing, PV, or risk (0.0455).
  • Basis points: For changes, it’s common to report deltas in basis points. Multiply a percent delta by 100 to get bp (e.g., a move from 4.55% to 4.65% is +10 bp). When storing bps, store as integers to avoid floating‑point surprises.

Dates and timestamps:

  • Curve snapshots are anchored to a market date. Use that field as the partition key in your data lake or time‑series DB.
  • “Latest” may return a timestamp or an as‑of date; always prefer the most explicit field returned. If you only have a date, treat it as the end‑of‑day snapshot for that market day in analytics.
  • Time zones: If the response includes only a calendar date, time zone is not applicable. If a timestamp is present, handle it as provided (e.g., parse as an ISO‑8601 string) and convert to the zone you need at the display edge.

Shipping to production: guardrails and patterns

A few patterns prevent most on‑call pages and allow you to trust your US_30Y integrations:

  • Schema awareness: Log the full JSON response shape during development and in a sample of production calls. If the provider adds fields, your code should ignore unknown keys gracefully.
  • Idempotent jobs: If you’re persisting daily “latest” values, write upserts keyed by (date, country, maturity). This prevents duplicates on retries.
  • Alerting: Alert on unexpected nulls or missing keys for US_30Y, but silence alerts for known market holidays or planned maintenance windows, which you can cross‑reference in your own calendar.
  • Cold starts: If serverless, warm your function periodically during trading hours to reduce p95 latency for dashboards.
  • Version control for data: Keep a small, auditable store (even a flat file) of the last N days of US_30Y returned by the API for backtesting changes or reconciling UI issues later.

When to switch from US_30Y to the curve endpoint

Start with US_30Y if your immediate requirement is a single chart, threshold alerting, or feeding a long‑duration discount rate into a valuation model. Switch to the curve endpoint if:

  • You need multiple points in one atomic snapshot (3M–30Y) to compute spreads, interpolation, or fitting.
  • Your models require belly/front calibration (e.g., bootstrapping). Getting all maturities in one payload ensures internal consistency.
  • You’re building a market monitor that shows relative moves of 2Y/5Y/10Y/30Y together. Fetching once avoids cross‑tick mismatches during volatile sessions.

The curve sample earlier demonstrates how maturities coexist in one response for a given date, including the 30‑year point you care about. For complete parameterization of the curve request, consult the documentation at bonds-api.com/docs and test interactively in MCP.

End‑to‑end checklist

Go live in four steps

  • Register for an account — includes a 7‑day trial: Register
  • Copy your api_key from your account dashboard.
  • Call GET https://bonds-api.com/api/v1/latest with countries=US, maturities=30Y, and your api_key.
  • Render the US_30Y value. If you need several points (e.g., 2Y/5Y/10Y/30Y together), switch to the curve endpoint so you have a single, consistent as‑of snapshot.

Data hygiene before shipping

  • Validate units: treat yields as percent for display and decimal for math.
  • Store as‑of dates: they are your reconciliation anchor across systems.
  • Cache the last good response to handle brief outages or inter‑request jitter.
  • Monitor for missing keys and non‑200 HTTP responses with actionable logs.

FAQ

Is this the same as Fed Funds or SOFR?
No. This is the US 30‑year Treasury yield (US_30Y), a sovereign bond yield. It is not a policy rate or overnight reference rate.

How are yields expressed in the response?
As shown in the official curve example, yields are presented in percent (e.g., 4.55 represents 4.55%). Convert to decimals for calculations if needed.

What happens on weekends or US market holidays?
On non‑trading days, do not expect a fresh intraday value. The “latest” endpoint will return the most recent available market day. Build your scheduler and alerts with the holiday calendar in mind.

How do I get multiple maturities (e.g., 2Y, 5Y, 10Y, 30Y) in one response?
Use the curve endpoint described in the documentation. The official sample in this article shows how several tenors appear together for a given market date, including the 30‑year point.

Where can I find parameters and known fields for production?
Refer to the documentation at bonds-api.com/docs and test requests in MCP before hardening your parser.

Ready to read the long bond yield in your own app? Create an account, copy your key, and call the latest endpoint for US_30Y. You can be streaming data to your charts or models in minutes: Register.

Start building with bond data today

Get your API key and access sovereign bond yields across 60+ countries. 7-day free trial, no credit card required.