US 2-Year Treasury Yield API: US_2Y as JSON

US 2-Year Treasury Yield API: US_2Y as JSON

You need the latest US 2-year Treasury yield inside your own code, not a chart or a PDF. By the end of this article you will request the US_2Y tenor from Bonds-API as JSON, read the fields you actually need, and ship a reliable integration that respects trading days, updates, and caching constraints.

What “US_2Y” means and when you need it

US_2Y is the two-year point on the US Treasury yield curve. It is a single tenor, not the whole curve, and it is frequently used in:

  • Short-rate expectation models and macro dashboards
  • Funding and ALM reports that pivot on the 2-year reference
  • Risk, PnL explain, and scenario tools where the 2-year anchor drives interpolation

On Bonds-API you query the 2-year yield specifically by setting maturities=2Y and reading the US_2Y field in the JSON. If you want the entire US curve instead, use the curve endpoint and read the US_2Y key from that envelope. This article focuses on the single-tenor call and how to work with the result in production.

Endpoint and authentication

The latest 2-year US Treasury yield is available via an HTTP GET:

  • Endpoint: https://bonds-api.com/api/v1/latest
  • Parameters: countries=US, maturities=2Y, api_key=YOUR_API_KEY

Authentication is passed as an api_key query parameter, not as a Bearer header.

If you prefer to receive the full US curve and pick the 2-year value from it, use GET /api/v1/curve?country=US. The response provides keys such as US_2Y that you can extract. The example JSON below comes from that curve envelope and is dated 2026-04-14, where the 2Y point prints 3.80.

Go live in four steps

  1. Register for an API key. The Starter plan is $19/mo (1,000 requests) and includes a 7-day trial.
  2. Copy your api_key from your account.
  3. Call the latest endpoint with countries=US and maturities=2Y.
  4. Parse the JSON and read the US_2Y field.

For general product information and updates, see bonds-api.com, and review the developer documentation at bonds-api.com/docs.

cURL: request the latest US 2-year yield

Copy, paste, and run this to fetch today’s 2-year print. Replace YOUR_API_KEY with your key.

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

JSON: what to read and how to interpret it

The JSON below shows an official US curve payload dated 2026-04-14. Although it’s a curve response, you’ll see the US_2Y field inside the same envelope you would parse from the latest endpoint when it returns tenor keys. Read the US_2Y value for the two-year yield.

{
  "success": true,
  "data": {
    "country": "US",
    "date": "2026-04-14",
    "curve": [
      {"maturity": "2Y", "yield": 3.80},
      {"maturity": "10Y", "yield": 4.25}
    ],
    "spread_2y_10y": 45.0,
    "inverted": false
  }
}

How to use this payload in your code:

  • US_2Y: numeric yield for the US 2-year Treasury. Yields are expressed in percent (for example, 3.80 means 3.80%). Do not multiply by 100 again.
  • Date: the response includes a clearly labeled date for the print (in this example, 2026-04-14). Use this to align your time series and caching.
  • If the response includes a timestamp alongside the date, treat it as the update time for that day’s print. Store it as UTC in your database and convert for display if needed.

Error handling and absent values:

  • Check the HTTP status code before parsing the body.
  • If the response body indicates a failure or an empty payload for a given day (for example, on market holidays), do not overwrite yesterday’s value. Keep your last known good value and try again after the next scheduled update.
  • Guard your parser so it fails gracefully if the US_2Y key is missing in the body you received.

Python example: fetch and parse US_2Y

This Python snippet sends the same GET request as the cURL above, extracts the US_2Y field, and reads the as-of date. Replace YOUR_API_KEY before running.

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

BASE = "https://bonds-api.com/api/v1/latest"
params = {
    "countries": "US",
    "maturities": "2Y",
    "api_key": os.environ.get("BONDS_API_KEY", "YOUR_API_KEY"),
}
url = f"{BASE}?{urllib.parse.urlencode(params)}"

try:
    with urllib.request.urlopen(url, timeout=10) as resp:
        if resp.status != 200:
            raise RuntimeError(f"HTTP {resp.status}")
        body = resp.read().decode("utf-8")
        data = json.loads(body)
except Exception as e:
    print(f"Request failed: {e}", file=sys.stderr)
    sys.exit(1)

# Read the two fields you actually need:
# - the 2Y yield under 'US_2Y'
# - the date field present in the response (commonly an ISO YYYY-MM-DD string)
us_2y = data.get("US_2Y")
as_of = data.get("date") or data.get("as_of") or data.get("timestamp")

if us_2y is None:
    print("US_2Y is missing in the response; keep last known value and retry later.", file=sys.stderr)
    sys.exit(2)

print(f"US_2Y yield: {us_2y} %")
if as_of:
    print(f"As of: {as_of}")

Operational details that save time in production

Units and interpretation

  • Yields are provided in percent (e.g., 3.80 means 3.80%).
  • Base currency for US_2Y is USD by definition of the instrument; you do not need to request or specify currency.

Business days and market holidays

  • US Treasury yields follow US market calendars. Expect no new print on US market holidays.
  • If you poll on a holiday or weekend, design your code to keep the prior business day’s value and avoid backfilling with nulls.

Update frequency and polling

  • Call the latest endpoint on business days. If you need intraday refresh logic, gate your polling with a backoff strategy and cache bust only when you detect a newer as-of date or timestamp in the response.
  • If your app serves many users, centralize polling on the server side and cache the JSON to reduce repeated external calls.

Caching strategy

  • Use the date (and timestamp if present) in the response as your cache key. Only invalidate when the date advances or the timestamp changes.
  • If you run batch jobs, schedule your fetch after your own day-cut to avoid race conditions with late-arriving updates.

Single tenor vs. full curve

  • For only the two-year yield: GET https://bonds-api.com/api/v1/latest with countries=US and maturities=2Y, then read US_2Y.
  • For the entire US curve in one call: GET /api/v1/curve?country=US and extract the US_2Y key from the JSON alongside other tenors. The example JSON above shows how the 2Y appears (3.80 on 2026-04-14).

Monitoring, retries, and fallbacks

  • Retries: Implement short, bounded retries on network errors. Do not retry on 4xx errors without changing the request.
  • Validation: Treat negative or non-numeric US_2Y as invalid and keep your last known value while alerting.
  • Backfills: If you maintain a time series, index records by the provided date so re-fetching the same day does not duplicate data.

Where to explore, test, and automate

  • Interactive exploration: Use the MCP endpoint list to understand endpoints and parameters in one place.
  • Developer documentation: Reference the full parameter and field descriptions at bonds-api.com/docs.
  • Product and status updates: Check bonds-api.com for product information.

Quality checks before shipping

  • Confirm your query: countries=US and maturities=2Y are both present; authentication is via api_key.
  • Guard parsing: assert that US_2Y exists and is a number; read the date from the response and store it as-is.
  • Respect non-trading days: no overwrite if you receive the same date as yesterday.
  • Document your cache policy: note the time you poll and the condition that triggers invalidation (date or timestamp change).

FAQ

Is this the policy rate (Fed Funds) or SOFR?
No. This is the US 2-year Treasury yield (US_2Y), a market yield on a US government bond, not an overnight policy or reference rate.

How are yields expressed in the JSON?
As percent values. For example, 3.80 means 3.80%. Do not multiply by 100 again.

What happens on US market holidays?
You should expect no new print. Keep your prior business day’s value and poll again on the next business day.

Can I get the full US curve and then read US_2Y from there?
Yes. Use GET /api/v1/curve?country=US and read the US_2Y key in the JSON. The example above shows how that looks for 2026-04-14.

How do I authenticate?
Pass your API key as a query parameter named api_key. Example: ...&api_key=YOUR_API_KEY

Ready to read US_2Y in your own code? Start a 7-day trial, get your key, and ship the integration today: 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.