curl https://api.nextmoca.com/v1/context/select \
-H "Authorization: Bearer $NEEDLEPATH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_id": "req-2026-09-03-0001",
"records": [
{
"id": "r-001",
"kind": "tool_result",
"title": "get_invoice(88231)",
"source": "billing-api",
"text": "{\"invoice_id\": 88231, \"account\": \"acct_4415\", \"total_cents\": 432000, \"currency\": \"usd\", \"status\": \"open\", \"issued\": \"2026-07-28\", \"due\": \"2026-08-27\", \"line_items\": [{\"sku\": \"NP-USAGE\", \"desc\": \"Metered input tokens, July\", \"qty\": 4800000, \"unit_price_cents\": 0.009}, {\"sku\": \"NP-SUPPORT\", \"desc\": \"Priority support\", \"qty\": 1, \"unit_price_cents\": 49900}]}"
},
{
"id": "r-002",
"kind": "tool_result",
"title": "get_account(acct_4415)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_4415\", \"name\": \"Meridian Analytics\", \"plan\": \"scale\", \"payment_method\": \"card_visa_6411\", \"delinquent\": false, \"since\": \"2025-11-03\", \"owner\": \"dana@meridiananalytics.com\"}"
},
{
"id": "r-003",
"kind": "external_data",
"title": "Data retention policy v3",
"source": "handbook",
"text": "Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility."
},
{
"id": "r-004",
"kind": "external_data",
"title": "Refund policy v4, section 2",
"source": "handbook",
"text": "Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible."
},
{
"id": "r-005",
"kind": "external_data",
"title": "Refund policy v4, section 3 (exceptions)",
"source": "handbook",
"text": "Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead'\''s discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered."
},
{
"id": "r-006",
"kind": "tool_result",
"title": "get_usage(acct_4415, july)",
"source": "metering-api",
"text": "{\"account_id\": \"acct_4415\", \"period\": \"2026-07\", \"input_tokens\": 4800000, \"requests\": 1210, \"stand_downs\": 34, \"charged_tokens\": 4646000}"
},
{
"id": "r-007",
"kind": "tool_result",
"title": "get_open_tickets(acct_9902)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5488\", \"subject\": \"API key rotation question\", \"opened\": \"2026-08-02\", \"status\": \"closed\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-008",
"kind": "user_input",
"title": null,
"source": null,
"text": "Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?"
},
{
"id": "r-009",
"kind": "external_data",
"title": "Credit policy v2",
"source": "handbook",
"text": "Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner'\''s written acknowledgement of the cause."
},
{
"id": "r-012",
"kind": "tool_result",
"title": "get_key_traffic(acct_4415, 2026-07-01..2026-07-19)",
"source": "metering-api",
"text": "{\"keys\": [{\"key_id\": \"np_key_a1\", \"requests\": 980, \"user_agent\": \"meridian-batch/2.1\", \"tokens\": 3100000}, {\"key_id\": \"np_key_b2\", \"requests\": 230, \"user_agent\": \"meridian-app/1.4\", \"tokens\": 1700000}], \"note\": \"np_key_a1 traffic stops 2026-07-19T14:02Z\"}"
},
{
"id": "r-013",
"kind": "external_data",
"title": "Q2 headcount planning notes",
"source": "internal-ops",
"text": "The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3."
},
{
"id": "r-014",
"kind": "tool_result",
"title": "get_invoice(55102)",
"source": "billing-api",
"text": "{\"invoice_id\": 55102, \"account\": \"acct_2210\", \"total_cents\": 18900, \"currency\": \"usd\", \"status\": \"paid\", \"issued\": \"2026-07-15\", \"due\": \"2026-08-14\"}"
},
{
"id": "r-015",
"kind": "external_data",
"title": "Q3 marketing newsletter draft",
"source": "marketing",
"text": "Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September."
},
{
"id": "r-016",
"kind": "external_data",
"title": "Office move logistics",
"source": "internal-ops",
"text": "The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes."
},
{
"id": "r-017",
"kind": "tool_result",
"title": "get_open_tickets(acct_4415)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5521\", \"subject\": \"July usage dispute\", \"opened\": \"2026-08-05\", \"status\": \"open\", \"assignee\": \"support-lead-2\"}]}"
},
{
"id": "r-018",
"kind": "tool_result",
"title": "get_open_tickets(acct_2210)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5502\", \"subject\": \"Login issue after SSO migration\", \"opened\": \"2026-08-01\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-019",
"kind": "external_data",
"title": "Vacation and PTO policy",
"source": "handbook",
"text": "Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect."
},
{
"id": "r-020",
"kind": "external_data",
"title": "Runbook: rotating a compromised API key",
"source": "ops-wiki",
"text": "If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes."
},
{
"id": "r-021",
"kind": "llm_response",
"text": "I'\''ve pulled up account acct_4415 and I'\''m reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown."
},
{
"id": "r-022",
"kind": "external_data",
"title": "Customer advisory board Q4 invite draft",
"source": "marketing",
"text": "Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support."
},
{
"id": "r-023",
"kind": "tool_result",
"title": "get_account(acct_9902)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_9902\", \"name\": \"Colby Fixtures\", \"plan\": \"growth\", \"payment_method\": \"card_mc_2290\", \"delinquent\": false, \"since\": \"2026-01-14\", \"owner\": \"ops@colbyfixtures.com\"}"
},
{
"id": "r-026",
"kind": "tool_result",
"title": "get_open_tickets(acct_5511)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5510\", \"subject\": \"Feature request: CSV export for usage analytics\", \"opened\": \"2026-08-03\", \"status\": \"open\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-027",
"kind": "external_data",
"title": "Q3 all-hands agenda",
"source": "internal-ops",
"text": "Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live."
},
{
"id": "r-029",
"kind": "external_data",
"title": "Marketing site refresh, visual only",
"source": "marketing",
"text": "The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only."
},
{
"id": "r-031",
"kind": "tool_result",
"title": "get_open_tickets(acct_6630)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5477\", \"subject\": \"Onboarding walkthrough request\", \"opened\": \"2026-07-30\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-032",
"kind": "external_data",
"title": "On-call rotation for September",
"source": "internal-ops",
"text": "September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead."
},
{
"id": "r-033",
"kind": "external_data",
"title": "Partner co-marketing webinar recap",
"source": "marketing",
"text": "Tuesday'\''s co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week."
},
{
"id": "r-034",
"kind": "external_data",
"title": "Conference room booking policy",
"source": "handbook",
"text": "Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing."
},
{
"id": "r-035",
"kind": "external_data",
"title": "Blog editorial calendar, Q4",
"source": "marketing",
"text": "Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication."
},
{
"id": "r-036",
"kind": "external_data",
"title": "Kitchen and supplies restock schedule",
"source": "internal-ops",
"text": "Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week."
}
],
"task": {
"prompt": "What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?",
"tool_name": "resolve_billing_dispute"
},
"budget": {
"max_context_tokens": 900,
"operating_point": "np-2026-08-r4"
},
"render": true,
"render_format": "plain",
"return_per_record": true
}'import os
import requests
payload = {
"request_id": "req-2026-09-03-0001",
"records": [
{
"id": "r-001",
"kind": "tool_result",
"title": "get_invoice(88231)",
"source": "billing-api",
"text": "{\"invoice_id\": 88231, \"account\": \"acct_4415\", \"total_cents\": 432000, \"currency\": \"usd\", \"status\": \"open\", \"issued\": \"2026-07-28\", \"due\": \"2026-08-27\", \"line_items\": [{\"sku\": \"NP-USAGE\", \"desc\": \"Metered input tokens, July\", \"qty\": 4800000, \"unit_price_cents\": 0.009}, {\"sku\": \"NP-SUPPORT\", \"desc\": \"Priority support\", \"qty\": 1, \"unit_price_cents\": 49900}]}",
},
{
"id": "r-002",
"kind": "tool_result",
"title": "get_account(acct_4415)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_4415\", \"name\": \"Meridian Analytics\", \"plan\": \"scale\", \"payment_method\": \"card_visa_6411\", \"delinquent\": false, \"since\": \"2025-11-03\", \"owner\": \"dana@meridiananalytics.com\"}",
},
{
"id": "r-003",
"kind": "external_data",
"title": "Data retention policy v3",
"source": "handbook",
"text": "Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.",
},
{
"id": "r-004",
"kind": "external_data",
"title": "Refund policy v4, section 2",
"source": "handbook",
"text": "Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.",
},
{
"id": "r-005",
"kind": "external_data",
"title": "Refund policy v4, section 3 (exceptions)",
"source": "handbook",
"text": "Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.",
},
{
"id": "r-006",
"kind": "tool_result",
"title": "get_usage(acct_4415, july)",
"source": "metering-api",
"text": "{\"account_id\": \"acct_4415\", \"period\": \"2026-07\", \"input_tokens\": 4800000, \"requests\": 1210, \"stand_downs\": 34, \"charged_tokens\": 4646000}",
},
{
"id": "r-007",
"kind": "tool_result",
"title": "get_open_tickets(acct_9902)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5488\", \"subject\": \"API key rotation question\", \"opened\": \"2026-08-02\", \"status\": \"closed\", \"assignee\": \"support-lead-1\"}]}",
},
{
"id": "r-008",
"kind": "user_input",
"title": None,
"source": None,
"text": "Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?",
},
{
"id": "r-009",
"kind": "external_data",
"title": "Credit policy v2",
"source": "handbook",
"text": "Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause.",
},
{
"id": "r-012",
"kind": "tool_result",
"title": "get_key_traffic(acct_4415, 2026-07-01..2026-07-19)",
"source": "metering-api",
"text": "{\"keys\": [{\"key_id\": \"np_key_a1\", \"requests\": 980, \"user_agent\": \"meridian-batch/2.1\", \"tokens\": 3100000}, {\"key_id\": \"np_key_b2\", \"requests\": 230, \"user_agent\": \"meridian-app/1.4\", \"tokens\": 1700000}], \"note\": \"np_key_a1 traffic stops 2026-07-19T14:02Z\"}",
},
{
"id": "r-013",
"kind": "external_data",
"title": "Q2 headcount planning notes",
"source": "internal-ops",
"text": "The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.",
},
{
"id": "r-014",
"kind": "tool_result",
"title": "get_invoice(55102)",
"source": "billing-api",
"text": "{\"invoice_id\": 55102, \"account\": \"acct_2210\", \"total_cents\": 18900, \"currency\": \"usd\", \"status\": \"paid\", \"issued\": \"2026-07-15\", \"due\": \"2026-08-14\"}",
},
{
"id": "r-015",
"kind": "external_data",
"title": "Q3 marketing newsletter draft",
"source": "marketing",
"text": "Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.",
},
{
"id": "r-016",
"kind": "external_data",
"title": "Office move logistics",
"source": "internal-ops",
"text": "The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.",
},
{
"id": "r-017",
"kind": "tool_result",
"title": "get_open_tickets(acct_4415)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5521\", \"subject\": \"July usage dispute\", \"opened\": \"2026-08-05\", \"status\": \"open\", \"assignee\": \"support-lead-2\"}]}",
},
{
"id": "r-018",
"kind": "tool_result",
"title": "get_open_tickets(acct_2210)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5502\", \"subject\": \"Login issue after SSO migration\", \"opened\": \"2026-08-01\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}",
},
{
"id": "r-019",
"kind": "external_data",
"title": "Vacation and PTO policy",
"source": "handbook",
"text": "Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.",
},
{
"id": "r-020",
"kind": "external_data",
"title": "Runbook: rotating a compromised API key",
"source": "ops-wiki",
"text": "If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.",
},
{
"id": "r-021",
"kind": "llm_response",
"text": "I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.",
},
{
"id": "r-022",
"kind": "external_data",
"title": "Customer advisory board Q4 invite draft",
"source": "marketing",
"text": "Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.",
},
{
"id": "r-023",
"kind": "tool_result",
"title": "get_account(acct_9902)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_9902\", \"name\": \"Colby Fixtures\", \"plan\": \"growth\", \"payment_method\": \"card_mc_2290\", \"delinquent\": false, \"since\": \"2026-01-14\", \"owner\": \"ops@colbyfixtures.com\"}",
},
{
"id": "r-026",
"kind": "tool_result",
"title": "get_open_tickets(acct_5511)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5510\", \"subject\": \"Feature request: CSV export for usage analytics\", \"opened\": \"2026-08-03\", \"status\": \"open\", \"assignee\": \"support-lead-1\"}]}",
},
{
"id": "r-027",
"kind": "external_data",
"title": "Q3 all-hands agenda",
"source": "internal-ops",
"text": "Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.",
},
{
"id": "r-029",
"kind": "external_data",
"title": "Marketing site refresh, visual only",
"source": "marketing",
"text": "The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.",
},
{
"id": "r-031",
"kind": "tool_result",
"title": "get_open_tickets(acct_6630)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5477\", \"subject\": \"Onboarding walkthrough request\", \"opened\": \"2026-07-30\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}",
},
{
"id": "r-032",
"kind": "external_data",
"title": "On-call rotation for September",
"source": "internal-ops",
"text": "September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.",
},
{
"id": "r-033",
"kind": "external_data",
"title": "Partner co-marketing webinar recap",
"source": "marketing",
"text": "Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.",
},
{
"id": "r-034",
"kind": "external_data",
"title": "Conference room booking policy",
"source": "handbook",
"text": "Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.",
},
{
"id": "r-035",
"kind": "external_data",
"title": "Blog editorial calendar, Q4",
"source": "marketing",
"text": "Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.",
},
{
"id": "r-036",
"kind": "external_data",
"title": "Kitchen and supplies restock schedule",
"source": "internal-ops",
"text": "Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.",
},
],
"task": {
"prompt": "What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?",
"tool_name": "resolve_billing_dispute",
},
"budget": {
"max_context_tokens": 900,
"operating_point": "np-2026-08-r4",
},
"render": True,
"render_format": "plain",
"return_per_record": True,
}
r = requests.post(
"https://api.nextmoca.com/v1/context/select",
headers={"Authorization": f"Bearer {os.environ['NEEDLEPATH_API_KEY']}"},
json=payload,
timeout=10,
)
r.raise_for_status()
result = r.json()
print(result["records_selected"], "selected,", result["tokens_saved"], "tokens saved")const payload = {
"request_id": "req-2026-09-03-0001",
"records": [
{
"id": "r-001",
"kind": "tool_result",
"title": "get_invoice(88231)",
"source": "billing-api",
"text": "{\"invoice_id\": 88231, \"account\": \"acct_4415\", \"total_cents\": 432000, \"currency\": \"usd\", \"status\": \"open\", \"issued\": \"2026-07-28\", \"due\": \"2026-08-27\", \"line_items\": [{\"sku\": \"NP-USAGE\", \"desc\": \"Metered input tokens, July\", \"qty\": 4800000, \"unit_price_cents\": 0.009}, {\"sku\": \"NP-SUPPORT\", \"desc\": \"Priority support\", \"qty\": 1, \"unit_price_cents\": 49900}]}"
},
{
"id": "r-002",
"kind": "tool_result",
"title": "get_account(acct_4415)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_4415\", \"name\": \"Meridian Analytics\", \"plan\": \"scale\", \"payment_method\": \"card_visa_6411\", \"delinquent\": false, \"since\": \"2025-11-03\", \"owner\": \"dana@meridiananalytics.com\"}"
},
{
"id": "r-003",
"kind": "external_data",
"title": "Data retention policy v3",
"source": "handbook",
"text": "Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility."
},
{
"id": "r-004",
"kind": "external_data",
"title": "Refund policy v4, section 2",
"source": "handbook",
"text": "Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible."
},
{
"id": "r-005",
"kind": "external_data",
"title": "Refund policy v4, section 3 (exceptions)",
"source": "handbook",
"text": "Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered."
},
{
"id": "r-006",
"kind": "tool_result",
"title": "get_usage(acct_4415, july)",
"source": "metering-api",
"text": "{\"account_id\": \"acct_4415\", \"period\": \"2026-07\", \"input_tokens\": 4800000, \"requests\": 1210, \"stand_downs\": 34, \"charged_tokens\": 4646000}"
},
{
"id": "r-007",
"kind": "tool_result",
"title": "get_open_tickets(acct_9902)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5488\", \"subject\": \"API key rotation question\", \"opened\": \"2026-08-02\", \"status\": \"closed\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-008",
"kind": "user_input",
"title": null,
"source": null,
"text": "Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?"
},
{
"id": "r-009",
"kind": "external_data",
"title": "Credit policy v2",
"source": "handbook",
"text": "Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause."
},
{
"id": "r-012",
"kind": "tool_result",
"title": "get_key_traffic(acct_4415, 2026-07-01..2026-07-19)",
"source": "metering-api",
"text": "{\"keys\": [{\"key_id\": \"np_key_a1\", \"requests\": 980, \"user_agent\": \"meridian-batch/2.1\", \"tokens\": 3100000}, {\"key_id\": \"np_key_b2\", \"requests\": 230, \"user_agent\": \"meridian-app/1.4\", \"tokens\": 1700000}], \"note\": \"np_key_a1 traffic stops 2026-07-19T14:02Z\"}"
},
{
"id": "r-013",
"kind": "external_data",
"title": "Q2 headcount planning notes",
"source": "internal-ops",
"text": "The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3."
},
{
"id": "r-014",
"kind": "tool_result",
"title": "get_invoice(55102)",
"source": "billing-api",
"text": "{\"invoice_id\": 55102, \"account\": \"acct_2210\", \"total_cents\": 18900, \"currency\": \"usd\", \"status\": \"paid\", \"issued\": \"2026-07-15\", \"due\": \"2026-08-14\"}"
},
{
"id": "r-015",
"kind": "external_data",
"title": "Q3 marketing newsletter draft",
"source": "marketing",
"text": "Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September."
},
{
"id": "r-016",
"kind": "external_data",
"title": "Office move logistics",
"source": "internal-ops",
"text": "The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes."
},
{
"id": "r-017",
"kind": "tool_result",
"title": "get_open_tickets(acct_4415)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5521\", \"subject\": \"July usage dispute\", \"opened\": \"2026-08-05\", \"status\": \"open\", \"assignee\": \"support-lead-2\"}]}"
},
{
"id": "r-018",
"kind": "tool_result",
"title": "get_open_tickets(acct_2210)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5502\", \"subject\": \"Login issue after SSO migration\", \"opened\": \"2026-08-01\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-019",
"kind": "external_data",
"title": "Vacation and PTO policy",
"source": "handbook",
"text": "Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect."
},
{
"id": "r-020",
"kind": "external_data",
"title": "Runbook: rotating a compromised API key",
"source": "ops-wiki",
"text": "If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes."
},
{
"id": "r-021",
"kind": "llm_response",
"text": "I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown."
},
{
"id": "r-022",
"kind": "external_data",
"title": "Customer advisory board Q4 invite draft",
"source": "marketing",
"text": "Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support."
},
{
"id": "r-023",
"kind": "tool_result",
"title": "get_account(acct_9902)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_9902\", \"name\": \"Colby Fixtures\", \"plan\": \"growth\", \"payment_method\": \"card_mc_2290\", \"delinquent\": false, \"since\": \"2026-01-14\", \"owner\": \"ops@colbyfixtures.com\"}"
},
{
"id": "r-026",
"kind": "tool_result",
"title": "get_open_tickets(acct_5511)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5510\", \"subject\": \"Feature request: CSV export for usage analytics\", \"opened\": \"2026-08-03\", \"status\": \"open\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-027",
"kind": "external_data",
"title": "Q3 all-hands agenda",
"source": "internal-ops",
"text": "Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live."
},
{
"id": "r-029",
"kind": "external_data",
"title": "Marketing site refresh, visual only",
"source": "marketing",
"text": "The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only."
},
{
"id": "r-031",
"kind": "tool_result",
"title": "get_open_tickets(acct_6630)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5477\", \"subject\": \"Onboarding walkthrough request\", \"opened\": \"2026-07-30\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-032",
"kind": "external_data",
"title": "On-call rotation for September",
"source": "internal-ops",
"text": "September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead."
},
{
"id": "r-033",
"kind": "external_data",
"title": "Partner co-marketing webinar recap",
"source": "marketing",
"text": "Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week."
},
{
"id": "r-034",
"kind": "external_data",
"title": "Conference room booking policy",
"source": "handbook",
"text": "Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing."
},
{
"id": "r-035",
"kind": "external_data",
"title": "Blog editorial calendar, Q4",
"source": "marketing",
"text": "Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication."
},
{
"id": "r-036",
"kind": "external_data",
"title": "Kitchen and supplies restock schedule",
"source": "internal-ops",
"text": "Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week."
}
],
"task": {
"prompt": "What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?",
"tool_name": "resolve_billing_dispute"
},
"budget": {
"max_context_tokens": 900,
"operating_point": "np-2026-08-r4"
},
"render": true,
"render_format": "plain",
"return_per_record": true
};
const res = await fetch("https://api.nextmoca.com/v1/context/select", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.NEEDLEPATH_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
const result = await res.json();
console.log(result.records_selected, "selected,", result.tokens_saved, "tokens saved");const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
request_id: 'req-2026-09-03-0001',
records: [
{
id: 'r-001',
kind: 'tool_result',
title: 'get_invoice(88231)',
source: 'billing-api',
text: '{"invoice_id": 88231, "account": "acct_4415", "total_cents": 432000, "currency": "usd", "status": "open", "issued": "2026-07-28", "due": "2026-08-27", "line_items": [{"sku": "NP-USAGE", "desc": "Metered input tokens, July", "qty": 4800000, "unit_price_cents": 0.009}, {"sku": "NP-SUPPORT", "desc": "Priority support", "qty": 1, "unit_price_cents": 49900}]}'
},
{
id: 'r-002',
kind: 'tool_result',
title: 'get_account(acct_4415)',
source: 'crm-api',
text: '{"account_id": "acct_4415", "name": "Meridian Analytics", "plan": "scale", "payment_method": "card_visa_6411", "delinquent": false, "since": "2025-11-03", "owner": "dana@meridiananalytics.com"}'
},
{
id: 'r-003',
kind: 'external_data',
title: 'Data retention policy v3',
source: 'handbook',
text: 'Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.'
},
{
id: 'r-004',
kind: 'external_data',
title: 'Refund policy v4, section 2',
source: 'handbook',
text: 'Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.'
},
{
id: 'r-005',
kind: 'external_data',
title: 'Refund policy v4, section 3 (exceptions)',
source: 'handbook',
text: 'Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead\'s discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.'
},
{
id: 'r-006',
kind: 'tool_result',
title: 'get_usage(acct_4415, july)',
source: 'metering-api',
text: '{"account_id": "acct_4415", "period": "2026-07", "input_tokens": 4800000, "requests": 1210, "stand_downs": 34, "charged_tokens": 4646000}'
},
{
id: 'r-007',
kind: 'tool_result',
title: 'get_open_tickets(acct_9902)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5488", "subject": "API key rotation question", "opened": "2026-08-02", "status": "closed", "assignee": "support-lead-1"}]}'
},
{
id: 'r-008',
kind: 'user_input',
title: null,
source: null,
text: 'Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?'
},
{
id: 'r-009',
kind: 'external_data',
title: 'Credit policy v2',
source: 'handbook',
text: 'Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner\'s written acknowledgement of the cause.'
},
{
id: 'r-012',
kind: 'tool_result',
title: 'get_key_traffic(acct_4415, 2026-07-01..2026-07-19)',
source: 'metering-api',
text: '{"keys": [{"key_id": "np_key_a1", "requests": 980, "user_agent": "meridian-batch/2.1", "tokens": 3100000}, {"key_id": "np_key_b2", "requests": 230, "user_agent": "meridian-app/1.4", "tokens": 1700000}], "note": "np_key_a1 traffic stops 2026-07-19T14:02Z"}'
},
{
id: 'r-013',
kind: 'external_data',
title: 'Q2 headcount planning notes',
source: 'internal-ops',
text: 'The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.'
},
{
id: 'r-014',
kind: 'tool_result',
title: 'get_invoice(55102)',
source: 'billing-api',
text: '{"invoice_id": 55102, "account": "acct_2210", "total_cents": 18900, "currency": "usd", "status": "paid", "issued": "2026-07-15", "due": "2026-08-14"}'
},
{
id: 'r-015',
kind: 'external_data',
title: 'Q3 marketing newsletter draft',
source: 'marketing',
text: 'Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.'
},
{
id: 'r-016',
kind: 'external_data',
title: 'Office move logistics',
source: 'internal-ops',
text: 'The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.'
},
{
id: 'r-017',
kind: 'tool_result',
title: 'get_open_tickets(acct_4415)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5521", "subject": "July usage dispute", "opened": "2026-08-05", "status": "open", "assignee": "support-lead-2"}]}'
},
{
id: 'r-018',
kind: 'tool_result',
title: 'get_open_tickets(acct_2210)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5502", "subject": "Login issue after SSO migration", "opened": "2026-08-01", "status": "closed", "assignee": "support-lead-3"}]}'
},
{
id: 'r-019',
kind: 'external_data',
title: 'Vacation and PTO policy',
source: 'handbook',
text: 'Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.'
},
{
id: 'r-020',
kind: 'external_data',
title: 'Runbook: rotating a compromised API key',
source: 'ops-wiki',
text: 'If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.'
},
{
id: 'r-021',
kind: 'llm_response',
text: 'I\'ve pulled up account acct_4415 and I\'m reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.'
},
{
id: 'r-022',
kind: 'external_data',
title: 'Customer advisory board Q4 invite draft',
source: 'marketing',
text: 'Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.'
},
{
id: 'r-023',
kind: 'tool_result',
title: 'get_account(acct_9902)',
source: 'crm-api',
text: '{"account_id": "acct_9902", "name": "Colby Fixtures", "plan": "growth", "payment_method": "card_mc_2290", "delinquent": false, "since": "2026-01-14", "owner": "ops@colbyfixtures.com"}'
},
{
id: 'r-026',
kind: 'tool_result',
title: 'get_open_tickets(acct_5511)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5510", "subject": "Feature request: CSV export for usage analytics", "opened": "2026-08-03", "status": "open", "assignee": "support-lead-1"}]}'
},
{
id: 'r-027',
kind: 'external_data',
title: 'Q3 all-hands agenda',
source: 'internal-ops',
text: 'Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.'
},
{
id: 'r-029',
kind: 'external_data',
title: 'Marketing site refresh, visual only',
source: 'marketing',
text: 'The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.'
},
{
id: 'r-031',
kind: 'tool_result',
title: 'get_open_tickets(acct_6630)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5477", "subject": "Onboarding walkthrough request", "opened": "2026-07-30", "status": "closed", "assignee": "support-lead-3"}]}'
},
{
id: 'r-032',
kind: 'external_data',
title: 'On-call rotation for September',
source: 'internal-ops',
text: 'September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.'
},
{
id: 'r-033',
kind: 'external_data',
title: 'Partner co-marketing webinar recap',
source: 'marketing',
text: 'Tuesday\'s co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.'
},
{
id: 'r-034',
kind: 'external_data',
title: 'Conference room booking policy',
source: 'handbook',
text: 'Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.'
},
{
id: 'r-035',
kind: 'external_data',
title: 'Blog editorial calendar, Q4',
source: 'marketing',
text: 'Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.'
},
{
id: 'r-036',
kind: 'external_data',
title: 'Kitchen and supplies restock schedule',
source: 'internal-ops',
text: 'Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.'
}
],
task: {
prompt: 'What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?',
tool_name: 'resolve_billing_dispute'
},
budget: {max_context_tokens: 900, operating_point: 'np-2026-08-r4'},
render: true,
render_format: 'plain',
return_per_record: true
})
};
fetch('https://api.nextmoca.com/v1/context/select', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.nextmoca.com/v1/context/select",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'request_id' => 'req-2026-09-03-0001',
'records' => [
[
'id' => 'r-001',
'kind' => 'tool_result',
'title' => 'get_invoice(88231)',
'source' => 'billing-api',
'text' => '{"invoice_id": 88231, "account": "acct_4415", "total_cents": 432000, "currency": "usd", "status": "open", "issued": "2026-07-28", "due": "2026-08-27", "line_items": [{"sku": "NP-USAGE", "desc": "Metered input tokens, July", "qty": 4800000, "unit_price_cents": 0.009}, {"sku": "NP-SUPPORT", "desc": "Priority support", "qty": 1, "unit_price_cents": 49900}]}'
],
[
'id' => 'r-002',
'kind' => 'tool_result',
'title' => 'get_account(acct_4415)',
'source' => 'crm-api',
'text' => '{"account_id": "acct_4415", "name": "Meridian Analytics", "plan": "scale", "payment_method": "card_visa_6411", "delinquent": false, "since": "2025-11-03", "owner": "dana@meridiananalytics.com"}'
],
[
'id' => 'r-003',
'kind' => 'external_data',
'title' => 'Data retention policy v3',
'source' => 'handbook',
'text' => 'Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.'
],
[
'id' => 'r-004',
'kind' => 'external_data',
'title' => 'Refund policy v4, section 2',
'source' => 'handbook',
'text' => 'Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.'
],
[
'id' => 'r-005',
'kind' => 'external_data',
'title' => 'Refund policy v4, section 3 (exceptions)',
'source' => 'handbook',
'text' => 'Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead\'s discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.'
],
[
'id' => 'r-006',
'kind' => 'tool_result',
'title' => 'get_usage(acct_4415, july)',
'source' => 'metering-api',
'text' => '{"account_id": "acct_4415", "period": "2026-07", "input_tokens": 4800000, "requests": 1210, "stand_downs": 34, "charged_tokens": 4646000}'
],
[
'id' => 'r-007',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_9902)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5488", "subject": "API key rotation question", "opened": "2026-08-02", "status": "closed", "assignee": "support-lead-1"}]}'
],
[
'id' => 'r-008',
'kind' => 'user_input',
'title' => null,
'source' => null,
'text' => 'Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?'
],
[
'id' => 'r-009',
'kind' => 'external_data',
'title' => 'Credit policy v2',
'source' => 'handbook',
'text' => 'Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner\'s written acknowledgement of the cause.'
],
[
'id' => 'r-012',
'kind' => 'tool_result',
'title' => 'get_key_traffic(acct_4415, 2026-07-01..2026-07-19)',
'source' => 'metering-api',
'text' => '{"keys": [{"key_id": "np_key_a1", "requests": 980, "user_agent": "meridian-batch/2.1", "tokens": 3100000}, {"key_id": "np_key_b2", "requests": 230, "user_agent": "meridian-app/1.4", "tokens": 1700000}], "note": "np_key_a1 traffic stops 2026-07-19T14:02Z"}'
],
[
'id' => 'r-013',
'kind' => 'external_data',
'title' => 'Q2 headcount planning notes',
'source' => 'internal-ops',
'text' => 'The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.'
],
[
'id' => 'r-014',
'kind' => 'tool_result',
'title' => 'get_invoice(55102)',
'source' => 'billing-api',
'text' => '{"invoice_id": 55102, "account": "acct_2210", "total_cents": 18900, "currency": "usd", "status": "paid", "issued": "2026-07-15", "due": "2026-08-14"}'
],
[
'id' => 'r-015',
'kind' => 'external_data',
'title' => 'Q3 marketing newsletter draft',
'source' => 'marketing',
'text' => 'Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.'
],
[
'id' => 'r-016',
'kind' => 'external_data',
'title' => 'Office move logistics',
'source' => 'internal-ops',
'text' => 'The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.'
],
[
'id' => 'r-017',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_4415)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5521", "subject": "July usage dispute", "opened": "2026-08-05", "status": "open", "assignee": "support-lead-2"}]}'
],
[
'id' => 'r-018',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_2210)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5502", "subject": "Login issue after SSO migration", "opened": "2026-08-01", "status": "closed", "assignee": "support-lead-3"}]}'
],
[
'id' => 'r-019',
'kind' => 'external_data',
'title' => 'Vacation and PTO policy',
'source' => 'handbook',
'text' => 'Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.'
],
[
'id' => 'r-020',
'kind' => 'external_data',
'title' => 'Runbook: rotating a compromised API key',
'source' => 'ops-wiki',
'text' => 'If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.'
],
[
'id' => 'r-021',
'kind' => 'llm_response',
'text' => 'I\'ve pulled up account acct_4415 and I\'m reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.'
],
[
'id' => 'r-022',
'kind' => 'external_data',
'title' => 'Customer advisory board Q4 invite draft',
'source' => 'marketing',
'text' => 'Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.'
],
[
'id' => 'r-023',
'kind' => 'tool_result',
'title' => 'get_account(acct_9902)',
'source' => 'crm-api',
'text' => '{"account_id": "acct_9902", "name": "Colby Fixtures", "plan": "growth", "payment_method": "card_mc_2290", "delinquent": false, "since": "2026-01-14", "owner": "ops@colbyfixtures.com"}'
],
[
'id' => 'r-026',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_5511)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5510", "subject": "Feature request: CSV export for usage analytics", "opened": "2026-08-03", "status": "open", "assignee": "support-lead-1"}]}'
],
[
'id' => 'r-027',
'kind' => 'external_data',
'title' => 'Q3 all-hands agenda',
'source' => 'internal-ops',
'text' => 'Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.'
],
[
'id' => 'r-029',
'kind' => 'external_data',
'title' => 'Marketing site refresh, visual only',
'source' => 'marketing',
'text' => 'The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.'
],
[
'id' => 'r-031',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_6630)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5477", "subject": "Onboarding walkthrough request", "opened": "2026-07-30", "status": "closed", "assignee": "support-lead-3"}]}'
],
[
'id' => 'r-032',
'kind' => 'external_data',
'title' => 'On-call rotation for September',
'source' => 'internal-ops',
'text' => 'September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.'
],
[
'id' => 'r-033',
'kind' => 'external_data',
'title' => 'Partner co-marketing webinar recap',
'source' => 'marketing',
'text' => 'Tuesday\'s co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.'
],
[
'id' => 'r-034',
'kind' => 'external_data',
'title' => 'Conference room booking policy',
'source' => 'handbook',
'text' => 'Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.'
],
[
'id' => 'r-035',
'kind' => 'external_data',
'title' => 'Blog editorial calendar, Q4',
'source' => 'marketing',
'text' => 'Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.'
],
[
'id' => 'r-036',
'kind' => 'external_data',
'title' => 'Kitchen and supplies restock schedule',
'source' => 'internal-ops',
'text' => 'Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.'
]
],
'task' => [
'prompt' => 'What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?',
'tool_name' => 'resolve_billing_dispute'
],
'budget' => [
'max_context_tokens' => 900,
'operating_point' => 'np-2026-08-r4'
],
'render' => true,
'render_format' => 'plain',
'return_per_record' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.nextmoca.com/v1/context/select"
payload := strings.NewReader("{\n \"request_id\": \"req-2026-09-03-0001\",\n \"records\": [\n {\n \"id\": \"r-001\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(88231)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 88231, \\\"account\\\": \\\"acct_4415\\\", \\\"total_cents\\\": 432000, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"open\\\", \\\"issued\\\": \\\"2026-07-28\\\", \\\"due\\\": \\\"2026-08-27\\\", \\\"line_items\\\": [{\\\"sku\\\": \\\"NP-USAGE\\\", \\\"desc\\\": \\\"Metered input tokens, July\\\", \\\"qty\\\": 4800000, \\\"unit_price_cents\\\": 0.009}, {\\\"sku\\\": \\\"NP-SUPPORT\\\", \\\"desc\\\": \\\"Priority support\\\", \\\"qty\\\": 1, \\\"unit_price_cents\\\": 49900}]}\"\n },\n {\n \"id\": \"r-002\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_4415)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"name\\\": \\\"Meridian Analytics\\\", \\\"plan\\\": \\\"scale\\\", \\\"payment_method\\\": \\\"card_visa_6411\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2025-11-03\\\", \\\"owner\\\": \\\"dana@meridiananalytics.com\\\"}\"\n },\n {\n \"id\": \"r-003\",\n \"kind\": \"external_data\",\n \"title\": \"Data retention policy v3\",\n \"source\": \"handbook\",\n \"text\": \"Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.\"\n },\n {\n \"id\": \"r-004\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 2\",\n \"source\": \"handbook\",\n \"text\": \"Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.\"\n },\n {\n \"id\": \"r-005\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 3 (exceptions)\",\n \"source\": \"handbook\",\n \"text\": \"Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.\"\n },\n {\n \"id\": \"r-006\",\n \"kind\": \"tool_result\",\n \"title\": \"get_usage(acct_4415, july)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"period\\\": \\\"2026-07\\\", \\\"input_tokens\\\": 4800000, \\\"requests\\\": 1210, \\\"stand_downs\\\": 34, \\\"charged_tokens\\\": 4646000}\"\n },\n {\n \"id\": \"r-007\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_9902)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5488\\\", \\\"subject\\\": \\\"API key rotation question\\\", \\\"opened\\\": \\\"2026-08-02\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-008\",\n \"kind\": \"user_input\",\n \"title\": null,\n \"source\": null,\n \"text\": \"Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?\"\n },\n {\n \"id\": \"r-009\",\n \"kind\": \"external_data\",\n \"title\": \"Credit policy v2\",\n \"source\": \"handbook\",\n \"text\": \"Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause.\"\n },\n {\n \"id\": \"r-012\",\n \"kind\": \"tool_result\",\n \"title\": \"get_key_traffic(acct_4415, 2026-07-01..2026-07-19)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"keys\\\": [{\\\"key_id\\\": \\\"np_key_a1\\\", \\\"requests\\\": 980, \\\"user_agent\\\": \\\"meridian-batch/2.1\\\", \\\"tokens\\\": 3100000}, {\\\"key_id\\\": \\\"np_key_b2\\\", \\\"requests\\\": 230, \\\"user_agent\\\": \\\"meridian-app/1.4\\\", \\\"tokens\\\": 1700000}], \\\"note\\\": \\\"np_key_a1 traffic stops 2026-07-19T14:02Z\\\"}\"\n },\n {\n \"id\": \"r-013\",\n \"kind\": \"external_data\",\n \"title\": \"Q2 headcount planning notes\",\n \"source\": \"internal-ops\",\n \"text\": \"The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.\"\n },\n {\n \"id\": \"r-014\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(55102)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 55102, \\\"account\\\": \\\"acct_2210\\\", \\\"total_cents\\\": 18900, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"paid\\\", \\\"issued\\\": \\\"2026-07-15\\\", \\\"due\\\": \\\"2026-08-14\\\"}\"\n },\n {\n \"id\": \"r-015\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 marketing newsletter draft\",\n \"source\": \"marketing\",\n \"text\": \"Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.\"\n },\n {\n \"id\": \"r-016\",\n \"kind\": \"external_data\",\n \"title\": \"Office move logistics\",\n \"source\": \"internal-ops\",\n \"text\": \"The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.\"\n },\n {\n \"id\": \"r-017\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_4415)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5521\\\", \\\"subject\\\": \\\"July usage dispute\\\", \\\"opened\\\": \\\"2026-08-05\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-2\\\"}]}\"\n },\n {\n \"id\": \"r-018\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_2210)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5502\\\", \\\"subject\\\": \\\"Login issue after SSO migration\\\", \\\"opened\\\": \\\"2026-08-01\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-019\",\n \"kind\": \"external_data\",\n \"title\": \"Vacation and PTO policy\",\n \"source\": \"handbook\",\n \"text\": \"Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.\"\n },\n {\n \"id\": \"r-020\",\n \"kind\": \"external_data\",\n \"title\": \"Runbook: rotating a compromised API key\",\n \"source\": \"ops-wiki\",\n \"text\": \"If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.\"\n },\n {\n \"id\": \"r-021\",\n \"kind\": \"llm_response\",\n \"text\": \"I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.\"\n },\n {\n \"id\": \"r-022\",\n \"kind\": \"external_data\",\n \"title\": \"Customer advisory board Q4 invite draft\",\n \"source\": \"marketing\",\n \"text\": \"Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.\"\n },\n {\n \"id\": \"r-023\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_9902)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_9902\\\", \\\"name\\\": \\\"Colby Fixtures\\\", \\\"plan\\\": \\\"growth\\\", \\\"payment_method\\\": \\\"card_mc_2290\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2026-01-14\\\", \\\"owner\\\": \\\"ops@colbyfixtures.com\\\"}\"\n },\n {\n \"id\": \"r-026\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_5511)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5510\\\", \\\"subject\\\": \\\"Feature request: CSV export for usage analytics\\\", \\\"opened\\\": \\\"2026-08-03\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-027\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 all-hands agenda\",\n \"source\": \"internal-ops\",\n \"text\": \"Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.\"\n },\n {\n \"id\": \"r-029\",\n \"kind\": \"external_data\",\n \"title\": \"Marketing site refresh, visual only\",\n \"source\": \"marketing\",\n \"text\": \"The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.\"\n },\n {\n \"id\": \"r-031\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_6630)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5477\\\", \\\"subject\\\": \\\"Onboarding walkthrough request\\\", \\\"opened\\\": \\\"2026-07-30\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-032\",\n \"kind\": \"external_data\",\n \"title\": \"On-call rotation for September\",\n \"source\": \"internal-ops\",\n \"text\": \"September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.\"\n },\n {\n \"id\": \"r-033\",\n \"kind\": \"external_data\",\n \"title\": \"Partner co-marketing webinar recap\",\n \"source\": \"marketing\",\n \"text\": \"Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.\"\n },\n {\n \"id\": \"r-034\",\n \"kind\": \"external_data\",\n \"title\": \"Conference room booking policy\",\n \"source\": \"handbook\",\n \"text\": \"Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.\"\n },\n {\n \"id\": \"r-035\",\n \"kind\": \"external_data\",\n \"title\": \"Blog editorial calendar, Q4\",\n \"source\": \"marketing\",\n \"text\": \"Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.\"\n },\n {\n \"id\": \"r-036\",\n \"kind\": \"external_data\",\n \"title\": \"Kitchen and supplies restock schedule\",\n \"source\": \"internal-ops\",\n \"text\": \"Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.\"\n }\n ],\n \"task\": {\n \"prompt\": \"What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?\",\n \"tool_name\": \"resolve_billing_dispute\"\n },\n \"budget\": {\n \"max_context_tokens\": 900,\n \"operating_point\": \"np-2026-08-r4\"\n },\n \"render\": true,\n \"render_format\": \"plain\",\n \"return_per_record\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.nextmoca.com/v1/context/select")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"request_id\": \"req-2026-09-03-0001\",\n \"records\": [\n {\n \"id\": \"r-001\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(88231)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 88231, \\\"account\\\": \\\"acct_4415\\\", \\\"total_cents\\\": 432000, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"open\\\", \\\"issued\\\": \\\"2026-07-28\\\", \\\"due\\\": \\\"2026-08-27\\\", \\\"line_items\\\": [{\\\"sku\\\": \\\"NP-USAGE\\\", \\\"desc\\\": \\\"Metered input tokens, July\\\", \\\"qty\\\": 4800000, \\\"unit_price_cents\\\": 0.009}, {\\\"sku\\\": \\\"NP-SUPPORT\\\", \\\"desc\\\": \\\"Priority support\\\", \\\"qty\\\": 1, \\\"unit_price_cents\\\": 49900}]}\"\n },\n {\n \"id\": \"r-002\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_4415)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"name\\\": \\\"Meridian Analytics\\\", \\\"plan\\\": \\\"scale\\\", \\\"payment_method\\\": \\\"card_visa_6411\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2025-11-03\\\", \\\"owner\\\": \\\"dana@meridiananalytics.com\\\"}\"\n },\n {\n \"id\": \"r-003\",\n \"kind\": \"external_data\",\n \"title\": \"Data retention policy v3\",\n \"source\": \"handbook\",\n \"text\": \"Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.\"\n },\n {\n \"id\": \"r-004\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 2\",\n \"source\": \"handbook\",\n \"text\": \"Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.\"\n },\n {\n \"id\": \"r-005\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 3 (exceptions)\",\n \"source\": \"handbook\",\n \"text\": \"Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.\"\n },\n {\n \"id\": \"r-006\",\n \"kind\": \"tool_result\",\n \"title\": \"get_usage(acct_4415, july)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"period\\\": \\\"2026-07\\\", \\\"input_tokens\\\": 4800000, \\\"requests\\\": 1210, \\\"stand_downs\\\": 34, \\\"charged_tokens\\\": 4646000}\"\n },\n {\n \"id\": \"r-007\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_9902)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5488\\\", \\\"subject\\\": \\\"API key rotation question\\\", \\\"opened\\\": \\\"2026-08-02\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-008\",\n \"kind\": \"user_input\",\n \"title\": null,\n \"source\": null,\n \"text\": \"Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?\"\n },\n {\n \"id\": \"r-009\",\n \"kind\": \"external_data\",\n \"title\": \"Credit policy v2\",\n \"source\": \"handbook\",\n \"text\": \"Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause.\"\n },\n {\n \"id\": \"r-012\",\n \"kind\": \"tool_result\",\n \"title\": \"get_key_traffic(acct_4415, 2026-07-01..2026-07-19)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"keys\\\": [{\\\"key_id\\\": \\\"np_key_a1\\\", \\\"requests\\\": 980, \\\"user_agent\\\": \\\"meridian-batch/2.1\\\", \\\"tokens\\\": 3100000}, {\\\"key_id\\\": \\\"np_key_b2\\\", \\\"requests\\\": 230, \\\"user_agent\\\": \\\"meridian-app/1.4\\\", \\\"tokens\\\": 1700000}], \\\"note\\\": \\\"np_key_a1 traffic stops 2026-07-19T14:02Z\\\"}\"\n },\n {\n \"id\": \"r-013\",\n \"kind\": \"external_data\",\n \"title\": \"Q2 headcount planning notes\",\n \"source\": \"internal-ops\",\n \"text\": \"The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.\"\n },\n {\n \"id\": \"r-014\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(55102)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 55102, \\\"account\\\": \\\"acct_2210\\\", \\\"total_cents\\\": 18900, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"paid\\\", \\\"issued\\\": \\\"2026-07-15\\\", \\\"due\\\": \\\"2026-08-14\\\"}\"\n },\n {\n \"id\": \"r-015\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 marketing newsletter draft\",\n \"source\": \"marketing\",\n \"text\": \"Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.\"\n },\n {\n \"id\": \"r-016\",\n \"kind\": \"external_data\",\n \"title\": \"Office move logistics\",\n \"source\": \"internal-ops\",\n \"text\": \"The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.\"\n },\n {\n \"id\": \"r-017\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_4415)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5521\\\", \\\"subject\\\": \\\"July usage dispute\\\", \\\"opened\\\": \\\"2026-08-05\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-2\\\"}]}\"\n },\n {\n \"id\": \"r-018\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_2210)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5502\\\", \\\"subject\\\": \\\"Login issue after SSO migration\\\", \\\"opened\\\": \\\"2026-08-01\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-019\",\n \"kind\": \"external_data\",\n \"title\": \"Vacation and PTO policy\",\n \"source\": \"handbook\",\n \"text\": \"Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.\"\n },\n {\n \"id\": \"r-020\",\n \"kind\": \"external_data\",\n \"title\": \"Runbook: rotating a compromised API key\",\n \"source\": \"ops-wiki\",\n \"text\": \"If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.\"\n },\n {\n \"id\": \"r-021\",\n \"kind\": \"llm_response\",\n \"text\": \"I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.\"\n },\n {\n \"id\": \"r-022\",\n \"kind\": \"external_data\",\n \"title\": \"Customer advisory board Q4 invite draft\",\n \"source\": \"marketing\",\n \"text\": \"Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.\"\n },\n {\n \"id\": \"r-023\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_9902)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_9902\\\", \\\"name\\\": \\\"Colby Fixtures\\\", \\\"plan\\\": \\\"growth\\\", \\\"payment_method\\\": \\\"card_mc_2290\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2026-01-14\\\", \\\"owner\\\": \\\"ops@colbyfixtures.com\\\"}\"\n },\n {\n \"id\": \"r-026\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_5511)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5510\\\", \\\"subject\\\": \\\"Feature request: CSV export for usage analytics\\\", \\\"opened\\\": \\\"2026-08-03\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-027\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 all-hands agenda\",\n \"source\": \"internal-ops\",\n \"text\": \"Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.\"\n },\n {\n \"id\": \"r-029\",\n \"kind\": \"external_data\",\n \"title\": \"Marketing site refresh, visual only\",\n \"source\": \"marketing\",\n \"text\": \"The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.\"\n },\n {\n \"id\": \"r-031\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_6630)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5477\\\", \\\"subject\\\": \\\"Onboarding walkthrough request\\\", \\\"opened\\\": \\\"2026-07-30\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-032\",\n \"kind\": \"external_data\",\n \"title\": \"On-call rotation for September\",\n \"source\": \"internal-ops\",\n \"text\": \"September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.\"\n },\n {\n \"id\": \"r-033\",\n \"kind\": \"external_data\",\n \"title\": \"Partner co-marketing webinar recap\",\n \"source\": \"marketing\",\n \"text\": \"Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.\"\n },\n {\n \"id\": \"r-034\",\n \"kind\": \"external_data\",\n \"title\": \"Conference room booking policy\",\n \"source\": \"handbook\",\n \"text\": \"Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.\"\n },\n {\n \"id\": \"r-035\",\n \"kind\": \"external_data\",\n \"title\": \"Blog editorial calendar, Q4\",\n \"source\": \"marketing\",\n \"text\": \"Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.\"\n },\n {\n \"id\": \"r-036\",\n \"kind\": \"external_data\",\n \"title\": \"Kitchen and supplies restock schedule\",\n \"source\": \"internal-ops\",\n \"text\": \"Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.\"\n }\n ],\n \"task\": {\n \"prompt\": \"What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?\",\n \"tool_name\": \"resolve_billing_dispute\"\n },\n \"budget\": {\n \"max_context_tokens\": 900,\n \"operating_point\": \"np-2026-08-r4\"\n },\n \"render\": true,\n \"render_format\": \"plain\",\n \"return_per_record\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.nextmoca.com/v1/context/select")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"request_id\": \"req-2026-09-03-0001\",\n \"records\": [\n {\n \"id\": \"r-001\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(88231)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 88231, \\\"account\\\": \\\"acct_4415\\\", \\\"total_cents\\\": 432000, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"open\\\", \\\"issued\\\": \\\"2026-07-28\\\", \\\"due\\\": \\\"2026-08-27\\\", \\\"line_items\\\": [{\\\"sku\\\": \\\"NP-USAGE\\\", \\\"desc\\\": \\\"Metered input tokens, July\\\", \\\"qty\\\": 4800000, \\\"unit_price_cents\\\": 0.009}, {\\\"sku\\\": \\\"NP-SUPPORT\\\", \\\"desc\\\": \\\"Priority support\\\", \\\"qty\\\": 1, \\\"unit_price_cents\\\": 49900}]}\"\n },\n {\n \"id\": \"r-002\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_4415)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"name\\\": \\\"Meridian Analytics\\\", \\\"plan\\\": \\\"scale\\\", \\\"payment_method\\\": \\\"card_visa_6411\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2025-11-03\\\", \\\"owner\\\": \\\"dana@meridiananalytics.com\\\"}\"\n },\n {\n \"id\": \"r-003\",\n \"kind\": \"external_data\",\n \"title\": \"Data retention policy v3\",\n \"source\": \"handbook\",\n \"text\": \"Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.\"\n },\n {\n \"id\": \"r-004\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 2\",\n \"source\": \"handbook\",\n \"text\": \"Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.\"\n },\n {\n \"id\": \"r-005\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 3 (exceptions)\",\n \"source\": \"handbook\",\n \"text\": \"Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.\"\n },\n {\n \"id\": \"r-006\",\n \"kind\": \"tool_result\",\n \"title\": \"get_usage(acct_4415, july)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"period\\\": \\\"2026-07\\\", \\\"input_tokens\\\": 4800000, \\\"requests\\\": 1210, \\\"stand_downs\\\": 34, \\\"charged_tokens\\\": 4646000}\"\n },\n {\n \"id\": \"r-007\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_9902)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5488\\\", \\\"subject\\\": \\\"API key rotation question\\\", \\\"opened\\\": \\\"2026-08-02\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-008\",\n \"kind\": \"user_input\",\n \"title\": null,\n \"source\": null,\n \"text\": \"Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?\"\n },\n {\n \"id\": \"r-009\",\n \"kind\": \"external_data\",\n \"title\": \"Credit policy v2\",\n \"source\": \"handbook\",\n \"text\": \"Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause.\"\n },\n {\n \"id\": \"r-012\",\n \"kind\": \"tool_result\",\n \"title\": \"get_key_traffic(acct_4415, 2026-07-01..2026-07-19)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"keys\\\": [{\\\"key_id\\\": \\\"np_key_a1\\\", \\\"requests\\\": 980, \\\"user_agent\\\": \\\"meridian-batch/2.1\\\", \\\"tokens\\\": 3100000}, {\\\"key_id\\\": \\\"np_key_b2\\\", \\\"requests\\\": 230, \\\"user_agent\\\": \\\"meridian-app/1.4\\\", \\\"tokens\\\": 1700000}], \\\"note\\\": \\\"np_key_a1 traffic stops 2026-07-19T14:02Z\\\"}\"\n },\n {\n \"id\": \"r-013\",\n \"kind\": \"external_data\",\n \"title\": \"Q2 headcount planning notes\",\n \"source\": \"internal-ops\",\n \"text\": \"The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.\"\n },\n {\n \"id\": \"r-014\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(55102)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 55102, \\\"account\\\": \\\"acct_2210\\\", \\\"total_cents\\\": 18900, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"paid\\\", \\\"issued\\\": \\\"2026-07-15\\\", \\\"due\\\": \\\"2026-08-14\\\"}\"\n },\n {\n \"id\": \"r-015\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 marketing newsletter draft\",\n \"source\": \"marketing\",\n \"text\": \"Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.\"\n },\n {\n \"id\": \"r-016\",\n \"kind\": \"external_data\",\n \"title\": \"Office move logistics\",\n \"source\": \"internal-ops\",\n \"text\": \"The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.\"\n },\n {\n \"id\": \"r-017\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_4415)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5521\\\", \\\"subject\\\": \\\"July usage dispute\\\", \\\"opened\\\": \\\"2026-08-05\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-2\\\"}]}\"\n },\n {\n \"id\": \"r-018\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_2210)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5502\\\", \\\"subject\\\": \\\"Login issue after SSO migration\\\", \\\"opened\\\": \\\"2026-08-01\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-019\",\n \"kind\": \"external_data\",\n \"title\": \"Vacation and PTO policy\",\n \"source\": \"handbook\",\n \"text\": \"Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.\"\n },\n {\n \"id\": \"r-020\",\n \"kind\": \"external_data\",\n \"title\": \"Runbook: rotating a compromised API key\",\n \"source\": \"ops-wiki\",\n \"text\": \"If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.\"\n },\n {\n \"id\": \"r-021\",\n \"kind\": \"llm_response\",\n \"text\": \"I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.\"\n },\n {\n \"id\": \"r-022\",\n \"kind\": \"external_data\",\n \"title\": \"Customer advisory board Q4 invite draft\",\n \"source\": \"marketing\",\n \"text\": \"Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.\"\n },\n {\n \"id\": \"r-023\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_9902)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_9902\\\", \\\"name\\\": \\\"Colby Fixtures\\\", \\\"plan\\\": \\\"growth\\\", \\\"payment_method\\\": \\\"card_mc_2290\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2026-01-14\\\", \\\"owner\\\": \\\"ops@colbyfixtures.com\\\"}\"\n },\n {\n \"id\": \"r-026\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_5511)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5510\\\", \\\"subject\\\": \\\"Feature request: CSV export for usage analytics\\\", \\\"opened\\\": \\\"2026-08-03\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-027\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 all-hands agenda\",\n \"source\": \"internal-ops\",\n \"text\": \"Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.\"\n },\n {\n \"id\": \"r-029\",\n \"kind\": \"external_data\",\n \"title\": \"Marketing site refresh, visual only\",\n \"source\": \"marketing\",\n \"text\": \"The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.\"\n },\n {\n \"id\": \"r-031\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_6630)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5477\\\", \\\"subject\\\": \\\"Onboarding walkthrough request\\\", \\\"opened\\\": \\\"2026-07-30\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-032\",\n \"kind\": \"external_data\",\n \"title\": \"On-call rotation for September\",\n \"source\": \"internal-ops\",\n \"text\": \"September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.\"\n },\n {\n \"id\": \"r-033\",\n \"kind\": \"external_data\",\n \"title\": \"Partner co-marketing webinar recap\",\n \"source\": \"marketing\",\n \"text\": \"Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.\"\n },\n {\n \"id\": \"r-034\",\n \"kind\": \"external_data\",\n \"title\": \"Conference room booking policy\",\n \"source\": \"handbook\",\n \"text\": \"Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.\"\n },\n {\n \"id\": \"r-035\",\n \"kind\": \"external_data\",\n \"title\": \"Blog editorial calendar, Q4\",\n \"source\": \"marketing\",\n \"text\": \"Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.\"\n },\n {\n \"id\": \"r-036\",\n \"kind\": \"external_data\",\n \"title\": \"Kitchen and supplies restock schedule\",\n \"source\": \"internal-ops\",\n \"text\": \"Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.\"\n }\n ],\n \"task\": {\n \"prompt\": \"What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?\",\n \"tool_name\": \"resolve_billing_dispute\"\n },\n \"budget\": {\n \"max_context_tokens\": 900,\n \"operating_point\": \"np-2026-08-r4\"\n },\n \"render\": true,\n \"render_format\": \"plain\",\n \"return_per_record\": true\n}"
response = http.request(request)
puts response.read_body{
"request_id": "req-2026-09-03-0001",
"rendered_context": "Relevant State\n\n1. Credit policy v2 (handbook)\nService credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method.\nCredits require the account owner's written acknowledgement of the cause.\n\n2. user_input\nCustomer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?\n\n3. Refund policy v4, section 3 (exceptions) (handbook)\nException: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.\n\n4. Refund policy v4, section 2 (handbook)\nRefunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.\n\n5. llm_response\nI've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.",
"policy_version": "np-2026-08-r4",
"selected": [
{
"record_id": "r-009",
"kind": "external_data",
"title": "Credit policy v2",
"source": "handbook",
"score": 32.658829095499584,
"reason": "hard context: answer-bearing evidence: keyword overlap",
"excerpt": "Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method.\nCredits require the account owner's written acknowledgement of the cause.",
"excerpt_format": "plain",
"selected_tokens": 76
},
{
"record_id": "r-008",
"kind": "user_input",
"title": null,
"source": null,
"score": 54.106697605930485,
"reason": "hard context: weighted evidence coverage: current request; keyword overlap; semantic tag overlap",
"excerpt": "Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?",
"excerpt_format": "plain",
"selected_tokens": 60
},
{
"record_id": "r-005",
"kind": "external_data",
"title": "Refund policy v4, section 3 (exceptions)",
"source": "handbook",
"score": 13.458636537340059,
"reason": "hard context: weighted evidence coverage: keyword overlap",
"excerpt": "Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.",
"excerpt_format": "plain",
"selected_tokens": 67
},
{
"record_id": "r-004",
"kind": "external_data",
"title": "Refund policy v4, section 2",
"source": "handbook",
"score": 14.01558939758398,
"reason": "hard context: recent relevant result: keyword overlap",
"excerpt": "Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.",
"excerpt_format": "plain",
"selected_tokens": 74
},
{
"record_id": "r-021",
"kind": "llm_response",
"title": null,
"source": null,
"score": 14.644259731672935,
"reason": "soft context: keyword overlap",
"excerpt": "I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.",
"excerpt_format": "plain",
"selected_tokens": 37
}
],
"tokens_before": 1775,
"tokens_after": 314,
"tokens_saved": 1461,
"records_available": 30,
"records_selected": 5,
"fallback_used": false,
"selection_error": null,
"engine_latency_ms": 7.534137000220653,
"budget_tokens": 900,
"attempted_budget_tokens": [
900
],
"reduction_ratio": 0.8230985915492958,
"safety": {
"selection_safe": true,
"fallback_required": false,
"fallback_reason": "",
"coverage_score": 1,
"evidence_shape": "exact_anchor_lookup",
"evidence_terms": null,
"repair_reasons": []
},
"gate": {
"engaged": true,
"reason": "engage:delivered_support_complete",
"signals": {
"n_candidates": 21,
"high_drift": false
}
},
"format_metrics": {
"context_format": "plain",
"formatted_context_tokens": 361,
"plain_context_tokens": 361,
"toon_context_tokens": null,
"toon_applied": false,
"whole_context_toon_applied": false,
"structured_toon_excerpts": 0,
"structured_toon_tokens_saved": 0,
"toon_tokens_saved_vs_plain": 0,
"selection_strategy_used": "fast",
"selection_strategy_initial": "fast",
"support_contract_used": "generic",
"adapter_attempt_count": 1,
"semantic_adapter_ids": [
"generic"
],
"semantic_routing_bounds_hit": false,
"semantic_adapter_registry_version": "np-adapters-2026-08-r1",
"semantic_router_version": "np-router-2026-08-r3",
"semantic_normalizer_version": "np-normalizer-2026-08-r1",
"support_contract_resolution_version": "np-support-resolution-2026-08-r3",
"attempted_recall_rungs": [
{
"candidate_limit": 250,
"min_selection_score": 8,
"max_selected_records": 18,
"max_selected_tokens": 900
}
]
},
"selection_strategy_used": "fast",
"support_contract_used": "generic",
"adapter_attempt_count": 1,
"usage": {
"meter_version": "npm-2026-08-r1",
"outcome": "engaged",
"input_tokens": 1998,
"charge_multiplier": "1.0",
"price_version": "npp-2026-08-r1",
"currency": "USD"
},
"outcome": "engaged",
"records_submitted": 30,
"records_admitted": 30,
"candidates_truncated": false,
"selection_recall": {
"version": "npsr-2026-08-r2",
"operating_point": "np-2026-08-r4",
"records_submitted": 30,
"records_admitted": 30,
"candidate_matches_total": 21,
"candidates_scored": 21,
"candidates_above_floor": 5,
"records_selected": 5,
"candidate_limit_hit": false,
"weighted_term_coverage": 0.4838709677419355,
"excerpt_term_coverage": 0.44086021505376344,
"rejection_counts": {
"hard_entity_conflict": 0,
"secret_payload": 0,
"below_selection_floor": 16,
"record_count_budget": 0,
"token_budget": 0,
"excerpt_coverage_loss": 0
},
"evidence_confidence_score": 1,
"lexical_coverage": 0.44086021505376344
},
"task_kind": "pointed"
}Select the records worth sending to a model
Send every record you are considering plus the task they must serve. Needlepath returns the subset it selected, together with a rendered block, per-record scores and reasons, and the token arithmetic.
Selection, not rewriting. Nothing is paraphrased or summarised into
new prose and no model writes replacement text; an excerpt is built from
the record’s own content. It is not guaranteed byte-identical to a
span of your input. See SelectedRecord.excerpt. If you need exact
spans, join on record_id and use your own copy.
Stateless. Records ride in on every request and nothing is persisted
between calls. The same request under the same operating_point gets
the same answer, with two caveats before you assert on it in a test:
that guarantee is scoped to the request exactly as sent, so record order
is part of it, and a record sent without an id comes back under a
freshly generated one. Send ids, and send a stable order.
A stand-down is a success. If the engine judges that trimming would
not pay, it returns your context essentially intact with
outcome = stood_down and fallback_used = true. Treat it as a normal
200 and send what you were going to send, and do not treat a low
tokens_saved as an error. Read outcome for this, never gate.
Fail open. If this call times out, returns non-2xx, or returns an empty selection, send your original context unmodified. It is a binding rule for every integration, first-party or yours.
curl https://api.nextmoca.com/v1/context/select \
-H "Authorization: Bearer $NEEDLEPATH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_id": "req-2026-09-03-0001",
"records": [
{
"id": "r-001",
"kind": "tool_result",
"title": "get_invoice(88231)",
"source": "billing-api",
"text": "{\"invoice_id\": 88231, \"account\": \"acct_4415\", \"total_cents\": 432000, \"currency\": \"usd\", \"status\": \"open\", \"issued\": \"2026-07-28\", \"due\": \"2026-08-27\", \"line_items\": [{\"sku\": \"NP-USAGE\", \"desc\": \"Metered input tokens, July\", \"qty\": 4800000, \"unit_price_cents\": 0.009}, {\"sku\": \"NP-SUPPORT\", \"desc\": \"Priority support\", \"qty\": 1, \"unit_price_cents\": 49900}]}"
},
{
"id": "r-002",
"kind": "tool_result",
"title": "get_account(acct_4415)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_4415\", \"name\": \"Meridian Analytics\", \"plan\": \"scale\", \"payment_method\": \"card_visa_6411\", \"delinquent\": false, \"since\": \"2025-11-03\", \"owner\": \"dana@meridiananalytics.com\"}"
},
{
"id": "r-003",
"kind": "external_data",
"title": "Data retention policy v3",
"source": "handbook",
"text": "Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility."
},
{
"id": "r-004",
"kind": "external_data",
"title": "Refund policy v4, section 2",
"source": "handbook",
"text": "Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible."
},
{
"id": "r-005",
"kind": "external_data",
"title": "Refund policy v4, section 3 (exceptions)",
"source": "handbook",
"text": "Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead'\''s discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered."
},
{
"id": "r-006",
"kind": "tool_result",
"title": "get_usage(acct_4415, july)",
"source": "metering-api",
"text": "{\"account_id\": \"acct_4415\", \"period\": \"2026-07\", \"input_tokens\": 4800000, \"requests\": 1210, \"stand_downs\": 34, \"charged_tokens\": 4646000}"
},
{
"id": "r-007",
"kind": "tool_result",
"title": "get_open_tickets(acct_9902)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5488\", \"subject\": \"API key rotation question\", \"opened\": \"2026-08-02\", \"status\": \"closed\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-008",
"kind": "user_input",
"title": null,
"source": null,
"text": "Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?"
},
{
"id": "r-009",
"kind": "external_data",
"title": "Credit policy v2",
"source": "handbook",
"text": "Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner'\''s written acknowledgement of the cause."
},
{
"id": "r-012",
"kind": "tool_result",
"title": "get_key_traffic(acct_4415, 2026-07-01..2026-07-19)",
"source": "metering-api",
"text": "{\"keys\": [{\"key_id\": \"np_key_a1\", \"requests\": 980, \"user_agent\": \"meridian-batch/2.1\", \"tokens\": 3100000}, {\"key_id\": \"np_key_b2\", \"requests\": 230, \"user_agent\": \"meridian-app/1.4\", \"tokens\": 1700000}], \"note\": \"np_key_a1 traffic stops 2026-07-19T14:02Z\"}"
},
{
"id": "r-013",
"kind": "external_data",
"title": "Q2 headcount planning notes",
"source": "internal-ops",
"text": "The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3."
},
{
"id": "r-014",
"kind": "tool_result",
"title": "get_invoice(55102)",
"source": "billing-api",
"text": "{\"invoice_id\": 55102, \"account\": \"acct_2210\", \"total_cents\": 18900, \"currency\": \"usd\", \"status\": \"paid\", \"issued\": \"2026-07-15\", \"due\": \"2026-08-14\"}"
},
{
"id": "r-015",
"kind": "external_data",
"title": "Q3 marketing newsletter draft",
"source": "marketing",
"text": "Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September."
},
{
"id": "r-016",
"kind": "external_data",
"title": "Office move logistics",
"source": "internal-ops",
"text": "The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes."
},
{
"id": "r-017",
"kind": "tool_result",
"title": "get_open_tickets(acct_4415)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5521\", \"subject\": \"July usage dispute\", \"opened\": \"2026-08-05\", \"status\": \"open\", \"assignee\": \"support-lead-2\"}]}"
},
{
"id": "r-018",
"kind": "tool_result",
"title": "get_open_tickets(acct_2210)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5502\", \"subject\": \"Login issue after SSO migration\", \"opened\": \"2026-08-01\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-019",
"kind": "external_data",
"title": "Vacation and PTO policy",
"source": "handbook",
"text": "Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect."
},
{
"id": "r-020",
"kind": "external_data",
"title": "Runbook: rotating a compromised API key",
"source": "ops-wiki",
"text": "If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes."
},
{
"id": "r-021",
"kind": "llm_response",
"text": "I'\''ve pulled up account acct_4415 and I'\''m reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown."
},
{
"id": "r-022",
"kind": "external_data",
"title": "Customer advisory board Q4 invite draft",
"source": "marketing",
"text": "Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support."
},
{
"id": "r-023",
"kind": "tool_result",
"title": "get_account(acct_9902)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_9902\", \"name\": \"Colby Fixtures\", \"plan\": \"growth\", \"payment_method\": \"card_mc_2290\", \"delinquent\": false, \"since\": \"2026-01-14\", \"owner\": \"ops@colbyfixtures.com\"}"
},
{
"id": "r-026",
"kind": "tool_result",
"title": "get_open_tickets(acct_5511)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5510\", \"subject\": \"Feature request: CSV export for usage analytics\", \"opened\": \"2026-08-03\", \"status\": \"open\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-027",
"kind": "external_data",
"title": "Q3 all-hands agenda",
"source": "internal-ops",
"text": "Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live."
},
{
"id": "r-029",
"kind": "external_data",
"title": "Marketing site refresh, visual only",
"source": "marketing",
"text": "The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only."
},
{
"id": "r-031",
"kind": "tool_result",
"title": "get_open_tickets(acct_6630)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5477\", \"subject\": \"Onboarding walkthrough request\", \"opened\": \"2026-07-30\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-032",
"kind": "external_data",
"title": "On-call rotation for September",
"source": "internal-ops",
"text": "September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead."
},
{
"id": "r-033",
"kind": "external_data",
"title": "Partner co-marketing webinar recap",
"source": "marketing",
"text": "Tuesday'\''s co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week."
},
{
"id": "r-034",
"kind": "external_data",
"title": "Conference room booking policy",
"source": "handbook",
"text": "Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing."
},
{
"id": "r-035",
"kind": "external_data",
"title": "Blog editorial calendar, Q4",
"source": "marketing",
"text": "Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication."
},
{
"id": "r-036",
"kind": "external_data",
"title": "Kitchen and supplies restock schedule",
"source": "internal-ops",
"text": "Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week."
}
],
"task": {
"prompt": "What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?",
"tool_name": "resolve_billing_dispute"
},
"budget": {
"max_context_tokens": 900,
"operating_point": "np-2026-08-r4"
},
"render": true,
"render_format": "plain",
"return_per_record": true
}'import os
import requests
payload = {
"request_id": "req-2026-09-03-0001",
"records": [
{
"id": "r-001",
"kind": "tool_result",
"title": "get_invoice(88231)",
"source": "billing-api",
"text": "{\"invoice_id\": 88231, \"account\": \"acct_4415\", \"total_cents\": 432000, \"currency\": \"usd\", \"status\": \"open\", \"issued\": \"2026-07-28\", \"due\": \"2026-08-27\", \"line_items\": [{\"sku\": \"NP-USAGE\", \"desc\": \"Metered input tokens, July\", \"qty\": 4800000, \"unit_price_cents\": 0.009}, {\"sku\": \"NP-SUPPORT\", \"desc\": \"Priority support\", \"qty\": 1, \"unit_price_cents\": 49900}]}",
},
{
"id": "r-002",
"kind": "tool_result",
"title": "get_account(acct_4415)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_4415\", \"name\": \"Meridian Analytics\", \"plan\": \"scale\", \"payment_method\": \"card_visa_6411\", \"delinquent\": false, \"since\": \"2025-11-03\", \"owner\": \"dana@meridiananalytics.com\"}",
},
{
"id": "r-003",
"kind": "external_data",
"title": "Data retention policy v3",
"source": "handbook",
"text": "Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.",
},
{
"id": "r-004",
"kind": "external_data",
"title": "Refund policy v4, section 2",
"source": "handbook",
"text": "Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.",
},
{
"id": "r-005",
"kind": "external_data",
"title": "Refund policy v4, section 3 (exceptions)",
"source": "handbook",
"text": "Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.",
},
{
"id": "r-006",
"kind": "tool_result",
"title": "get_usage(acct_4415, july)",
"source": "metering-api",
"text": "{\"account_id\": \"acct_4415\", \"period\": \"2026-07\", \"input_tokens\": 4800000, \"requests\": 1210, \"stand_downs\": 34, \"charged_tokens\": 4646000}",
},
{
"id": "r-007",
"kind": "tool_result",
"title": "get_open_tickets(acct_9902)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5488\", \"subject\": \"API key rotation question\", \"opened\": \"2026-08-02\", \"status\": \"closed\", \"assignee\": \"support-lead-1\"}]}",
},
{
"id": "r-008",
"kind": "user_input",
"title": None,
"source": None,
"text": "Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?",
},
{
"id": "r-009",
"kind": "external_data",
"title": "Credit policy v2",
"source": "handbook",
"text": "Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause.",
},
{
"id": "r-012",
"kind": "tool_result",
"title": "get_key_traffic(acct_4415, 2026-07-01..2026-07-19)",
"source": "metering-api",
"text": "{\"keys\": [{\"key_id\": \"np_key_a1\", \"requests\": 980, \"user_agent\": \"meridian-batch/2.1\", \"tokens\": 3100000}, {\"key_id\": \"np_key_b2\", \"requests\": 230, \"user_agent\": \"meridian-app/1.4\", \"tokens\": 1700000}], \"note\": \"np_key_a1 traffic stops 2026-07-19T14:02Z\"}",
},
{
"id": "r-013",
"kind": "external_data",
"title": "Q2 headcount planning notes",
"source": "internal-ops",
"text": "The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.",
},
{
"id": "r-014",
"kind": "tool_result",
"title": "get_invoice(55102)",
"source": "billing-api",
"text": "{\"invoice_id\": 55102, \"account\": \"acct_2210\", \"total_cents\": 18900, \"currency\": \"usd\", \"status\": \"paid\", \"issued\": \"2026-07-15\", \"due\": \"2026-08-14\"}",
},
{
"id": "r-015",
"kind": "external_data",
"title": "Q3 marketing newsletter draft",
"source": "marketing",
"text": "Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.",
},
{
"id": "r-016",
"kind": "external_data",
"title": "Office move logistics",
"source": "internal-ops",
"text": "The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.",
},
{
"id": "r-017",
"kind": "tool_result",
"title": "get_open_tickets(acct_4415)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5521\", \"subject\": \"July usage dispute\", \"opened\": \"2026-08-05\", \"status\": \"open\", \"assignee\": \"support-lead-2\"}]}",
},
{
"id": "r-018",
"kind": "tool_result",
"title": "get_open_tickets(acct_2210)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5502\", \"subject\": \"Login issue after SSO migration\", \"opened\": \"2026-08-01\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}",
},
{
"id": "r-019",
"kind": "external_data",
"title": "Vacation and PTO policy",
"source": "handbook",
"text": "Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.",
},
{
"id": "r-020",
"kind": "external_data",
"title": "Runbook: rotating a compromised API key",
"source": "ops-wiki",
"text": "If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.",
},
{
"id": "r-021",
"kind": "llm_response",
"text": "I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.",
},
{
"id": "r-022",
"kind": "external_data",
"title": "Customer advisory board Q4 invite draft",
"source": "marketing",
"text": "Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.",
},
{
"id": "r-023",
"kind": "tool_result",
"title": "get_account(acct_9902)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_9902\", \"name\": \"Colby Fixtures\", \"plan\": \"growth\", \"payment_method\": \"card_mc_2290\", \"delinquent\": false, \"since\": \"2026-01-14\", \"owner\": \"ops@colbyfixtures.com\"}",
},
{
"id": "r-026",
"kind": "tool_result",
"title": "get_open_tickets(acct_5511)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5510\", \"subject\": \"Feature request: CSV export for usage analytics\", \"opened\": \"2026-08-03\", \"status\": \"open\", \"assignee\": \"support-lead-1\"}]}",
},
{
"id": "r-027",
"kind": "external_data",
"title": "Q3 all-hands agenda",
"source": "internal-ops",
"text": "Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.",
},
{
"id": "r-029",
"kind": "external_data",
"title": "Marketing site refresh, visual only",
"source": "marketing",
"text": "The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.",
},
{
"id": "r-031",
"kind": "tool_result",
"title": "get_open_tickets(acct_6630)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5477\", \"subject\": \"Onboarding walkthrough request\", \"opened\": \"2026-07-30\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}",
},
{
"id": "r-032",
"kind": "external_data",
"title": "On-call rotation for September",
"source": "internal-ops",
"text": "September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.",
},
{
"id": "r-033",
"kind": "external_data",
"title": "Partner co-marketing webinar recap",
"source": "marketing",
"text": "Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.",
},
{
"id": "r-034",
"kind": "external_data",
"title": "Conference room booking policy",
"source": "handbook",
"text": "Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.",
},
{
"id": "r-035",
"kind": "external_data",
"title": "Blog editorial calendar, Q4",
"source": "marketing",
"text": "Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.",
},
{
"id": "r-036",
"kind": "external_data",
"title": "Kitchen and supplies restock schedule",
"source": "internal-ops",
"text": "Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.",
},
],
"task": {
"prompt": "What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?",
"tool_name": "resolve_billing_dispute",
},
"budget": {
"max_context_tokens": 900,
"operating_point": "np-2026-08-r4",
},
"render": True,
"render_format": "plain",
"return_per_record": True,
}
r = requests.post(
"https://api.nextmoca.com/v1/context/select",
headers={"Authorization": f"Bearer {os.environ['NEEDLEPATH_API_KEY']}"},
json=payload,
timeout=10,
)
r.raise_for_status()
result = r.json()
print(result["records_selected"], "selected,", result["tokens_saved"], "tokens saved")const payload = {
"request_id": "req-2026-09-03-0001",
"records": [
{
"id": "r-001",
"kind": "tool_result",
"title": "get_invoice(88231)",
"source": "billing-api",
"text": "{\"invoice_id\": 88231, \"account\": \"acct_4415\", \"total_cents\": 432000, \"currency\": \"usd\", \"status\": \"open\", \"issued\": \"2026-07-28\", \"due\": \"2026-08-27\", \"line_items\": [{\"sku\": \"NP-USAGE\", \"desc\": \"Metered input tokens, July\", \"qty\": 4800000, \"unit_price_cents\": 0.009}, {\"sku\": \"NP-SUPPORT\", \"desc\": \"Priority support\", \"qty\": 1, \"unit_price_cents\": 49900}]}"
},
{
"id": "r-002",
"kind": "tool_result",
"title": "get_account(acct_4415)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_4415\", \"name\": \"Meridian Analytics\", \"plan\": \"scale\", \"payment_method\": \"card_visa_6411\", \"delinquent\": false, \"since\": \"2025-11-03\", \"owner\": \"dana@meridiananalytics.com\"}"
},
{
"id": "r-003",
"kind": "external_data",
"title": "Data retention policy v3",
"source": "handbook",
"text": "Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility."
},
{
"id": "r-004",
"kind": "external_data",
"title": "Refund policy v4, section 2",
"source": "handbook",
"text": "Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible."
},
{
"id": "r-005",
"kind": "external_data",
"title": "Refund policy v4, section 3 (exceptions)",
"source": "handbook",
"text": "Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered."
},
{
"id": "r-006",
"kind": "tool_result",
"title": "get_usage(acct_4415, july)",
"source": "metering-api",
"text": "{\"account_id\": \"acct_4415\", \"period\": \"2026-07\", \"input_tokens\": 4800000, \"requests\": 1210, \"stand_downs\": 34, \"charged_tokens\": 4646000}"
},
{
"id": "r-007",
"kind": "tool_result",
"title": "get_open_tickets(acct_9902)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5488\", \"subject\": \"API key rotation question\", \"opened\": \"2026-08-02\", \"status\": \"closed\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-008",
"kind": "user_input",
"title": null,
"source": null,
"text": "Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?"
},
{
"id": "r-009",
"kind": "external_data",
"title": "Credit policy v2",
"source": "handbook",
"text": "Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause."
},
{
"id": "r-012",
"kind": "tool_result",
"title": "get_key_traffic(acct_4415, 2026-07-01..2026-07-19)",
"source": "metering-api",
"text": "{\"keys\": [{\"key_id\": \"np_key_a1\", \"requests\": 980, \"user_agent\": \"meridian-batch/2.1\", \"tokens\": 3100000}, {\"key_id\": \"np_key_b2\", \"requests\": 230, \"user_agent\": \"meridian-app/1.4\", \"tokens\": 1700000}], \"note\": \"np_key_a1 traffic stops 2026-07-19T14:02Z\"}"
},
{
"id": "r-013",
"kind": "external_data",
"title": "Q2 headcount planning notes",
"source": "internal-ops",
"text": "The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3."
},
{
"id": "r-014",
"kind": "tool_result",
"title": "get_invoice(55102)",
"source": "billing-api",
"text": "{\"invoice_id\": 55102, \"account\": \"acct_2210\", \"total_cents\": 18900, \"currency\": \"usd\", \"status\": \"paid\", \"issued\": \"2026-07-15\", \"due\": \"2026-08-14\"}"
},
{
"id": "r-015",
"kind": "external_data",
"title": "Q3 marketing newsletter draft",
"source": "marketing",
"text": "Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September."
},
{
"id": "r-016",
"kind": "external_data",
"title": "Office move logistics",
"source": "internal-ops",
"text": "The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes."
},
{
"id": "r-017",
"kind": "tool_result",
"title": "get_open_tickets(acct_4415)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5521\", \"subject\": \"July usage dispute\", \"opened\": \"2026-08-05\", \"status\": \"open\", \"assignee\": \"support-lead-2\"}]}"
},
{
"id": "r-018",
"kind": "tool_result",
"title": "get_open_tickets(acct_2210)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5502\", \"subject\": \"Login issue after SSO migration\", \"opened\": \"2026-08-01\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-019",
"kind": "external_data",
"title": "Vacation and PTO policy",
"source": "handbook",
"text": "Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect."
},
{
"id": "r-020",
"kind": "external_data",
"title": "Runbook: rotating a compromised API key",
"source": "ops-wiki",
"text": "If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes."
},
{
"id": "r-021",
"kind": "llm_response",
"text": "I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown."
},
{
"id": "r-022",
"kind": "external_data",
"title": "Customer advisory board Q4 invite draft",
"source": "marketing",
"text": "Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support."
},
{
"id": "r-023",
"kind": "tool_result",
"title": "get_account(acct_9902)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_9902\", \"name\": \"Colby Fixtures\", \"plan\": \"growth\", \"payment_method\": \"card_mc_2290\", \"delinquent\": false, \"since\": \"2026-01-14\", \"owner\": \"ops@colbyfixtures.com\"}"
},
{
"id": "r-026",
"kind": "tool_result",
"title": "get_open_tickets(acct_5511)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5510\", \"subject\": \"Feature request: CSV export for usage analytics\", \"opened\": \"2026-08-03\", \"status\": \"open\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-027",
"kind": "external_data",
"title": "Q3 all-hands agenda",
"source": "internal-ops",
"text": "Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live."
},
{
"id": "r-029",
"kind": "external_data",
"title": "Marketing site refresh, visual only",
"source": "marketing",
"text": "The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only."
},
{
"id": "r-031",
"kind": "tool_result",
"title": "get_open_tickets(acct_6630)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5477\", \"subject\": \"Onboarding walkthrough request\", \"opened\": \"2026-07-30\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-032",
"kind": "external_data",
"title": "On-call rotation for September",
"source": "internal-ops",
"text": "September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead."
},
{
"id": "r-033",
"kind": "external_data",
"title": "Partner co-marketing webinar recap",
"source": "marketing",
"text": "Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week."
},
{
"id": "r-034",
"kind": "external_data",
"title": "Conference room booking policy",
"source": "handbook",
"text": "Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing."
},
{
"id": "r-035",
"kind": "external_data",
"title": "Blog editorial calendar, Q4",
"source": "marketing",
"text": "Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication."
},
{
"id": "r-036",
"kind": "external_data",
"title": "Kitchen and supplies restock schedule",
"source": "internal-ops",
"text": "Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week."
}
],
"task": {
"prompt": "What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?",
"tool_name": "resolve_billing_dispute"
},
"budget": {
"max_context_tokens": 900,
"operating_point": "np-2026-08-r4"
},
"render": true,
"render_format": "plain",
"return_per_record": true
};
const res = await fetch("https://api.nextmoca.com/v1/context/select", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.NEEDLEPATH_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
const result = await res.json();
console.log(result.records_selected, "selected,", result.tokens_saved, "tokens saved");const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
request_id: 'req-2026-09-03-0001',
records: [
{
id: 'r-001',
kind: 'tool_result',
title: 'get_invoice(88231)',
source: 'billing-api',
text: '{"invoice_id": 88231, "account": "acct_4415", "total_cents": 432000, "currency": "usd", "status": "open", "issued": "2026-07-28", "due": "2026-08-27", "line_items": [{"sku": "NP-USAGE", "desc": "Metered input tokens, July", "qty": 4800000, "unit_price_cents": 0.009}, {"sku": "NP-SUPPORT", "desc": "Priority support", "qty": 1, "unit_price_cents": 49900}]}'
},
{
id: 'r-002',
kind: 'tool_result',
title: 'get_account(acct_4415)',
source: 'crm-api',
text: '{"account_id": "acct_4415", "name": "Meridian Analytics", "plan": "scale", "payment_method": "card_visa_6411", "delinquent": false, "since": "2025-11-03", "owner": "dana@meridiananalytics.com"}'
},
{
id: 'r-003',
kind: 'external_data',
title: 'Data retention policy v3',
source: 'handbook',
text: 'Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.'
},
{
id: 'r-004',
kind: 'external_data',
title: 'Refund policy v4, section 2',
source: 'handbook',
text: 'Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.'
},
{
id: 'r-005',
kind: 'external_data',
title: 'Refund policy v4, section 3 (exceptions)',
source: 'handbook',
text: 'Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead\'s discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.'
},
{
id: 'r-006',
kind: 'tool_result',
title: 'get_usage(acct_4415, july)',
source: 'metering-api',
text: '{"account_id": "acct_4415", "period": "2026-07", "input_tokens": 4800000, "requests": 1210, "stand_downs": 34, "charged_tokens": 4646000}'
},
{
id: 'r-007',
kind: 'tool_result',
title: 'get_open_tickets(acct_9902)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5488", "subject": "API key rotation question", "opened": "2026-08-02", "status": "closed", "assignee": "support-lead-1"}]}'
},
{
id: 'r-008',
kind: 'user_input',
title: null,
source: null,
text: 'Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?'
},
{
id: 'r-009',
kind: 'external_data',
title: 'Credit policy v2',
source: 'handbook',
text: 'Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner\'s written acknowledgement of the cause.'
},
{
id: 'r-012',
kind: 'tool_result',
title: 'get_key_traffic(acct_4415, 2026-07-01..2026-07-19)',
source: 'metering-api',
text: '{"keys": [{"key_id": "np_key_a1", "requests": 980, "user_agent": "meridian-batch/2.1", "tokens": 3100000}, {"key_id": "np_key_b2", "requests": 230, "user_agent": "meridian-app/1.4", "tokens": 1700000}], "note": "np_key_a1 traffic stops 2026-07-19T14:02Z"}'
},
{
id: 'r-013',
kind: 'external_data',
title: 'Q2 headcount planning notes',
source: 'internal-ops',
text: 'The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.'
},
{
id: 'r-014',
kind: 'tool_result',
title: 'get_invoice(55102)',
source: 'billing-api',
text: '{"invoice_id": 55102, "account": "acct_2210", "total_cents": 18900, "currency": "usd", "status": "paid", "issued": "2026-07-15", "due": "2026-08-14"}'
},
{
id: 'r-015',
kind: 'external_data',
title: 'Q3 marketing newsletter draft',
source: 'marketing',
text: 'Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.'
},
{
id: 'r-016',
kind: 'external_data',
title: 'Office move logistics',
source: 'internal-ops',
text: 'The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.'
},
{
id: 'r-017',
kind: 'tool_result',
title: 'get_open_tickets(acct_4415)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5521", "subject": "July usage dispute", "opened": "2026-08-05", "status": "open", "assignee": "support-lead-2"}]}'
},
{
id: 'r-018',
kind: 'tool_result',
title: 'get_open_tickets(acct_2210)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5502", "subject": "Login issue after SSO migration", "opened": "2026-08-01", "status": "closed", "assignee": "support-lead-3"}]}'
},
{
id: 'r-019',
kind: 'external_data',
title: 'Vacation and PTO policy',
source: 'handbook',
text: 'Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.'
},
{
id: 'r-020',
kind: 'external_data',
title: 'Runbook: rotating a compromised API key',
source: 'ops-wiki',
text: 'If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.'
},
{
id: 'r-021',
kind: 'llm_response',
text: 'I\'ve pulled up account acct_4415 and I\'m reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.'
},
{
id: 'r-022',
kind: 'external_data',
title: 'Customer advisory board Q4 invite draft',
source: 'marketing',
text: 'Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.'
},
{
id: 'r-023',
kind: 'tool_result',
title: 'get_account(acct_9902)',
source: 'crm-api',
text: '{"account_id": "acct_9902", "name": "Colby Fixtures", "plan": "growth", "payment_method": "card_mc_2290", "delinquent": false, "since": "2026-01-14", "owner": "ops@colbyfixtures.com"}'
},
{
id: 'r-026',
kind: 'tool_result',
title: 'get_open_tickets(acct_5511)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5510", "subject": "Feature request: CSV export for usage analytics", "opened": "2026-08-03", "status": "open", "assignee": "support-lead-1"}]}'
},
{
id: 'r-027',
kind: 'external_data',
title: 'Q3 all-hands agenda',
source: 'internal-ops',
text: 'Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.'
},
{
id: 'r-029',
kind: 'external_data',
title: 'Marketing site refresh, visual only',
source: 'marketing',
text: 'The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.'
},
{
id: 'r-031',
kind: 'tool_result',
title: 'get_open_tickets(acct_6630)',
source: 'support-api',
text: '{"tickets": [{"id": "T-5477", "subject": "Onboarding walkthrough request", "opened": "2026-07-30", "status": "closed", "assignee": "support-lead-3"}]}'
},
{
id: 'r-032',
kind: 'external_data',
title: 'On-call rotation for September',
source: 'internal-ops',
text: 'September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.'
},
{
id: 'r-033',
kind: 'external_data',
title: 'Partner co-marketing webinar recap',
source: 'marketing',
text: 'Tuesday\'s co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.'
},
{
id: 'r-034',
kind: 'external_data',
title: 'Conference room booking policy',
source: 'handbook',
text: 'Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.'
},
{
id: 'r-035',
kind: 'external_data',
title: 'Blog editorial calendar, Q4',
source: 'marketing',
text: 'Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.'
},
{
id: 'r-036',
kind: 'external_data',
title: 'Kitchen and supplies restock schedule',
source: 'internal-ops',
text: 'Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.'
}
],
task: {
prompt: 'What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?',
tool_name: 'resolve_billing_dispute'
},
budget: {max_context_tokens: 900, operating_point: 'np-2026-08-r4'},
render: true,
render_format: 'plain',
return_per_record: true
})
};
fetch('https://api.nextmoca.com/v1/context/select', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.nextmoca.com/v1/context/select",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'request_id' => 'req-2026-09-03-0001',
'records' => [
[
'id' => 'r-001',
'kind' => 'tool_result',
'title' => 'get_invoice(88231)',
'source' => 'billing-api',
'text' => '{"invoice_id": 88231, "account": "acct_4415", "total_cents": 432000, "currency": "usd", "status": "open", "issued": "2026-07-28", "due": "2026-08-27", "line_items": [{"sku": "NP-USAGE", "desc": "Metered input tokens, July", "qty": 4800000, "unit_price_cents": 0.009}, {"sku": "NP-SUPPORT", "desc": "Priority support", "qty": 1, "unit_price_cents": 49900}]}'
],
[
'id' => 'r-002',
'kind' => 'tool_result',
'title' => 'get_account(acct_4415)',
'source' => 'crm-api',
'text' => '{"account_id": "acct_4415", "name": "Meridian Analytics", "plan": "scale", "payment_method": "card_visa_6411", "delinquent": false, "since": "2025-11-03", "owner": "dana@meridiananalytics.com"}'
],
[
'id' => 'r-003',
'kind' => 'external_data',
'title' => 'Data retention policy v3',
'source' => 'handbook',
'text' => 'Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.'
],
[
'id' => 'r-004',
'kind' => 'external_data',
'title' => 'Refund policy v4, section 2',
'source' => 'handbook',
'text' => 'Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.'
],
[
'id' => 'r-005',
'kind' => 'external_data',
'title' => 'Refund policy v4, section 3 (exceptions)',
'source' => 'handbook',
'text' => 'Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead\'s discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.'
],
[
'id' => 'r-006',
'kind' => 'tool_result',
'title' => 'get_usage(acct_4415, july)',
'source' => 'metering-api',
'text' => '{"account_id": "acct_4415", "period": "2026-07", "input_tokens": 4800000, "requests": 1210, "stand_downs": 34, "charged_tokens": 4646000}'
],
[
'id' => 'r-007',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_9902)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5488", "subject": "API key rotation question", "opened": "2026-08-02", "status": "closed", "assignee": "support-lead-1"}]}'
],
[
'id' => 'r-008',
'kind' => 'user_input',
'title' => null,
'source' => null,
'text' => 'Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?'
],
[
'id' => 'r-009',
'kind' => 'external_data',
'title' => 'Credit policy v2',
'source' => 'handbook',
'text' => 'Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner\'s written acknowledgement of the cause.'
],
[
'id' => 'r-012',
'kind' => 'tool_result',
'title' => 'get_key_traffic(acct_4415, 2026-07-01..2026-07-19)',
'source' => 'metering-api',
'text' => '{"keys": [{"key_id": "np_key_a1", "requests": 980, "user_agent": "meridian-batch/2.1", "tokens": 3100000}, {"key_id": "np_key_b2", "requests": 230, "user_agent": "meridian-app/1.4", "tokens": 1700000}], "note": "np_key_a1 traffic stops 2026-07-19T14:02Z"}'
],
[
'id' => 'r-013',
'kind' => 'external_data',
'title' => 'Q2 headcount planning notes',
'source' => 'internal-ops',
'text' => 'The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.'
],
[
'id' => 'r-014',
'kind' => 'tool_result',
'title' => 'get_invoice(55102)',
'source' => 'billing-api',
'text' => '{"invoice_id": 55102, "account": "acct_2210", "total_cents": 18900, "currency": "usd", "status": "paid", "issued": "2026-07-15", "due": "2026-08-14"}'
],
[
'id' => 'r-015',
'kind' => 'external_data',
'title' => 'Q3 marketing newsletter draft',
'source' => 'marketing',
'text' => 'Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.'
],
[
'id' => 'r-016',
'kind' => 'external_data',
'title' => 'Office move logistics',
'source' => 'internal-ops',
'text' => 'The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.'
],
[
'id' => 'r-017',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_4415)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5521", "subject": "July usage dispute", "opened": "2026-08-05", "status": "open", "assignee": "support-lead-2"}]}'
],
[
'id' => 'r-018',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_2210)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5502", "subject": "Login issue after SSO migration", "opened": "2026-08-01", "status": "closed", "assignee": "support-lead-3"}]}'
],
[
'id' => 'r-019',
'kind' => 'external_data',
'title' => 'Vacation and PTO policy',
'source' => 'handbook',
'text' => 'Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.'
],
[
'id' => 'r-020',
'kind' => 'external_data',
'title' => 'Runbook: rotating a compromised API key',
'source' => 'ops-wiki',
'text' => 'If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.'
],
[
'id' => 'r-021',
'kind' => 'llm_response',
'text' => 'I\'ve pulled up account acct_4415 and I\'m reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.'
],
[
'id' => 'r-022',
'kind' => 'external_data',
'title' => 'Customer advisory board Q4 invite draft',
'source' => 'marketing',
'text' => 'Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.'
],
[
'id' => 'r-023',
'kind' => 'tool_result',
'title' => 'get_account(acct_9902)',
'source' => 'crm-api',
'text' => '{"account_id": "acct_9902", "name": "Colby Fixtures", "plan": "growth", "payment_method": "card_mc_2290", "delinquent": false, "since": "2026-01-14", "owner": "ops@colbyfixtures.com"}'
],
[
'id' => 'r-026',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_5511)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5510", "subject": "Feature request: CSV export for usage analytics", "opened": "2026-08-03", "status": "open", "assignee": "support-lead-1"}]}'
],
[
'id' => 'r-027',
'kind' => 'external_data',
'title' => 'Q3 all-hands agenda',
'source' => 'internal-ops',
'text' => 'Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.'
],
[
'id' => 'r-029',
'kind' => 'external_data',
'title' => 'Marketing site refresh, visual only',
'source' => 'marketing',
'text' => 'The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.'
],
[
'id' => 'r-031',
'kind' => 'tool_result',
'title' => 'get_open_tickets(acct_6630)',
'source' => 'support-api',
'text' => '{"tickets": [{"id": "T-5477", "subject": "Onboarding walkthrough request", "opened": "2026-07-30", "status": "closed", "assignee": "support-lead-3"}]}'
],
[
'id' => 'r-032',
'kind' => 'external_data',
'title' => 'On-call rotation for September',
'source' => 'internal-ops',
'text' => 'September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.'
],
[
'id' => 'r-033',
'kind' => 'external_data',
'title' => 'Partner co-marketing webinar recap',
'source' => 'marketing',
'text' => 'Tuesday\'s co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.'
],
[
'id' => 'r-034',
'kind' => 'external_data',
'title' => 'Conference room booking policy',
'source' => 'handbook',
'text' => 'Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.'
],
[
'id' => 'r-035',
'kind' => 'external_data',
'title' => 'Blog editorial calendar, Q4',
'source' => 'marketing',
'text' => 'Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.'
],
[
'id' => 'r-036',
'kind' => 'external_data',
'title' => 'Kitchen and supplies restock schedule',
'source' => 'internal-ops',
'text' => 'Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.'
]
],
'task' => [
'prompt' => 'What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?',
'tool_name' => 'resolve_billing_dispute'
],
'budget' => [
'max_context_tokens' => 900,
'operating_point' => 'np-2026-08-r4'
],
'render' => true,
'render_format' => 'plain',
'return_per_record' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.nextmoca.com/v1/context/select"
payload := strings.NewReader("{\n \"request_id\": \"req-2026-09-03-0001\",\n \"records\": [\n {\n \"id\": \"r-001\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(88231)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 88231, \\\"account\\\": \\\"acct_4415\\\", \\\"total_cents\\\": 432000, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"open\\\", \\\"issued\\\": \\\"2026-07-28\\\", \\\"due\\\": \\\"2026-08-27\\\", \\\"line_items\\\": [{\\\"sku\\\": \\\"NP-USAGE\\\", \\\"desc\\\": \\\"Metered input tokens, July\\\", \\\"qty\\\": 4800000, \\\"unit_price_cents\\\": 0.009}, {\\\"sku\\\": \\\"NP-SUPPORT\\\", \\\"desc\\\": \\\"Priority support\\\", \\\"qty\\\": 1, \\\"unit_price_cents\\\": 49900}]}\"\n },\n {\n \"id\": \"r-002\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_4415)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"name\\\": \\\"Meridian Analytics\\\", \\\"plan\\\": \\\"scale\\\", \\\"payment_method\\\": \\\"card_visa_6411\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2025-11-03\\\", \\\"owner\\\": \\\"dana@meridiananalytics.com\\\"}\"\n },\n {\n \"id\": \"r-003\",\n \"kind\": \"external_data\",\n \"title\": \"Data retention policy v3\",\n \"source\": \"handbook\",\n \"text\": \"Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.\"\n },\n {\n \"id\": \"r-004\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 2\",\n \"source\": \"handbook\",\n \"text\": \"Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.\"\n },\n {\n \"id\": \"r-005\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 3 (exceptions)\",\n \"source\": \"handbook\",\n \"text\": \"Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.\"\n },\n {\n \"id\": \"r-006\",\n \"kind\": \"tool_result\",\n \"title\": \"get_usage(acct_4415, july)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"period\\\": \\\"2026-07\\\", \\\"input_tokens\\\": 4800000, \\\"requests\\\": 1210, \\\"stand_downs\\\": 34, \\\"charged_tokens\\\": 4646000}\"\n },\n {\n \"id\": \"r-007\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_9902)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5488\\\", \\\"subject\\\": \\\"API key rotation question\\\", \\\"opened\\\": \\\"2026-08-02\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-008\",\n \"kind\": \"user_input\",\n \"title\": null,\n \"source\": null,\n \"text\": \"Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?\"\n },\n {\n \"id\": \"r-009\",\n \"kind\": \"external_data\",\n \"title\": \"Credit policy v2\",\n \"source\": \"handbook\",\n \"text\": \"Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause.\"\n },\n {\n \"id\": \"r-012\",\n \"kind\": \"tool_result\",\n \"title\": \"get_key_traffic(acct_4415, 2026-07-01..2026-07-19)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"keys\\\": [{\\\"key_id\\\": \\\"np_key_a1\\\", \\\"requests\\\": 980, \\\"user_agent\\\": \\\"meridian-batch/2.1\\\", \\\"tokens\\\": 3100000}, {\\\"key_id\\\": \\\"np_key_b2\\\", \\\"requests\\\": 230, \\\"user_agent\\\": \\\"meridian-app/1.4\\\", \\\"tokens\\\": 1700000}], \\\"note\\\": \\\"np_key_a1 traffic stops 2026-07-19T14:02Z\\\"}\"\n },\n {\n \"id\": \"r-013\",\n \"kind\": \"external_data\",\n \"title\": \"Q2 headcount planning notes\",\n \"source\": \"internal-ops\",\n \"text\": \"The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.\"\n },\n {\n \"id\": \"r-014\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(55102)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 55102, \\\"account\\\": \\\"acct_2210\\\", \\\"total_cents\\\": 18900, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"paid\\\", \\\"issued\\\": \\\"2026-07-15\\\", \\\"due\\\": \\\"2026-08-14\\\"}\"\n },\n {\n \"id\": \"r-015\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 marketing newsletter draft\",\n \"source\": \"marketing\",\n \"text\": \"Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.\"\n },\n {\n \"id\": \"r-016\",\n \"kind\": \"external_data\",\n \"title\": \"Office move logistics\",\n \"source\": \"internal-ops\",\n \"text\": \"The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.\"\n },\n {\n \"id\": \"r-017\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_4415)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5521\\\", \\\"subject\\\": \\\"July usage dispute\\\", \\\"opened\\\": \\\"2026-08-05\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-2\\\"}]}\"\n },\n {\n \"id\": \"r-018\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_2210)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5502\\\", \\\"subject\\\": \\\"Login issue after SSO migration\\\", \\\"opened\\\": \\\"2026-08-01\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-019\",\n \"kind\": \"external_data\",\n \"title\": \"Vacation and PTO policy\",\n \"source\": \"handbook\",\n \"text\": \"Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.\"\n },\n {\n \"id\": \"r-020\",\n \"kind\": \"external_data\",\n \"title\": \"Runbook: rotating a compromised API key\",\n \"source\": \"ops-wiki\",\n \"text\": \"If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.\"\n },\n {\n \"id\": \"r-021\",\n \"kind\": \"llm_response\",\n \"text\": \"I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.\"\n },\n {\n \"id\": \"r-022\",\n \"kind\": \"external_data\",\n \"title\": \"Customer advisory board Q4 invite draft\",\n \"source\": \"marketing\",\n \"text\": \"Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.\"\n },\n {\n \"id\": \"r-023\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_9902)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_9902\\\", \\\"name\\\": \\\"Colby Fixtures\\\", \\\"plan\\\": \\\"growth\\\", \\\"payment_method\\\": \\\"card_mc_2290\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2026-01-14\\\", \\\"owner\\\": \\\"ops@colbyfixtures.com\\\"}\"\n },\n {\n \"id\": \"r-026\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_5511)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5510\\\", \\\"subject\\\": \\\"Feature request: CSV export for usage analytics\\\", \\\"opened\\\": \\\"2026-08-03\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-027\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 all-hands agenda\",\n \"source\": \"internal-ops\",\n \"text\": \"Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.\"\n },\n {\n \"id\": \"r-029\",\n \"kind\": \"external_data\",\n \"title\": \"Marketing site refresh, visual only\",\n \"source\": \"marketing\",\n \"text\": \"The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.\"\n },\n {\n \"id\": \"r-031\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_6630)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5477\\\", \\\"subject\\\": \\\"Onboarding walkthrough request\\\", \\\"opened\\\": \\\"2026-07-30\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-032\",\n \"kind\": \"external_data\",\n \"title\": \"On-call rotation for September\",\n \"source\": \"internal-ops\",\n \"text\": \"September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.\"\n },\n {\n \"id\": \"r-033\",\n \"kind\": \"external_data\",\n \"title\": \"Partner co-marketing webinar recap\",\n \"source\": \"marketing\",\n \"text\": \"Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.\"\n },\n {\n \"id\": \"r-034\",\n \"kind\": \"external_data\",\n \"title\": \"Conference room booking policy\",\n \"source\": \"handbook\",\n \"text\": \"Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.\"\n },\n {\n \"id\": \"r-035\",\n \"kind\": \"external_data\",\n \"title\": \"Blog editorial calendar, Q4\",\n \"source\": \"marketing\",\n \"text\": \"Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.\"\n },\n {\n \"id\": \"r-036\",\n \"kind\": \"external_data\",\n \"title\": \"Kitchen and supplies restock schedule\",\n \"source\": \"internal-ops\",\n \"text\": \"Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.\"\n }\n ],\n \"task\": {\n \"prompt\": \"What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?\",\n \"tool_name\": \"resolve_billing_dispute\"\n },\n \"budget\": {\n \"max_context_tokens\": 900,\n \"operating_point\": \"np-2026-08-r4\"\n },\n \"render\": true,\n \"render_format\": \"plain\",\n \"return_per_record\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.nextmoca.com/v1/context/select")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"request_id\": \"req-2026-09-03-0001\",\n \"records\": [\n {\n \"id\": \"r-001\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(88231)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 88231, \\\"account\\\": \\\"acct_4415\\\", \\\"total_cents\\\": 432000, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"open\\\", \\\"issued\\\": \\\"2026-07-28\\\", \\\"due\\\": \\\"2026-08-27\\\", \\\"line_items\\\": [{\\\"sku\\\": \\\"NP-USAGE\\\", \\\"desc\\\": \\\"Metered input tokens, July\\\", \\\"qty\\\": 4800000, \\\"unit_price_cents\\\": 0.009}, {\\\"sku\\\": \\\"NP-SUPPORT\\\", \\\"desc\\\": \\\"Priority support\\\", \\\"qty\\\": 1, \\\"unit_price_cents\\\": 49900}]}\"\n },\n {\n \"id\": \"r-002\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_4415)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"name\\\": \\\"Meridian Analytics\\\", \\\"plan\\\": \\\"scale\\\", \\\"payment_method\\\": \\\"card_visa_6411\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2025-11-03\\\", \\\"owner\\\": \\\"dana@meridiananalytics.com\\\"}\"\n },\n {\n \"id\": \"r-003\",\n \"kind\": \"external_data\",\n \"title\": \"Data retention policy v3\",\n \"source\": \"handbook\",\n \"text\": \"Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.\"\n },\n {\n \"id\": \"r-004\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 2\",\n \"source\": \"handbook\",\n \"text\": \"Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.\"\n },\n {\n \"id\": \"r-005\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 3 (exceptions)\",\n \"source\": \"handbook\",\n \"text\": \"Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.\"\n },\n {\n \"id\": \"r-006\",\n \"kind\": \"tool_result\",\n \"title\": \"get_usage(acct_4415, july)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"period\\\": \\\"2026-07\\\", \\\"input_tokens\\\": 4800000, \\\"requests\\\": 1210, \\\"stand_downs\\\": 34, \\\"charged_tokens\\\": 4646000}\"\n },\n {\n \"id\": \"r-007\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_9902)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5488\\\", \\\"subject\\\": \\\"API key rotation question\\\", \\\"opened\\\": \\\"2026-08-02\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-008\",\n \"kind\": \"user_input\",\n \"title\": null,\n \"source\": null,\n \"text\": \"Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?\"\n },\n {\n \"id\": \"r-009\",\n \"kind\": \"external_data\",\n \"title\": \"Credit policy v2\",\n \"source\": \"handbook\",\n \"text\": \"Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause.\"\n },\n {\n \"id\": \"r-012\",\n \"kind\": \"tool_result\",\n \"title\": \"get_key_traffic(acct_4415, 2026-07-01..2026-07-19)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"keys\\\": [{\\\"key_id\\\": \\\"np_key_a1\\\", \\\"requests\\\": 980, \\\"user_agent\\\": \\\"meridian-batch/2.1\\\", \\\"tokens\\\": 3100000}, {\\\"key_id\\\": \\\"np_key_b2\\\", \\\"requests\\\": 230, \\\"user_agent\\\": \\\"meridian-app/1.4\\\", \\\"tokens\\\": 1700000}], \\\"note\\\": \\\"np_key_a1 traffic stops 2026-07-19T14:02Z\\\"}\"\n },\n {\n \"id\": \"r-013\",\n \"kind\": \"external_data\",\n \"title\": \"Q2 headcount planning notes\",\n \"source\": \"internal-ops\",\n \"text\": \"The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.\"\n },\n {\n \"id\": \"r-014\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(55102)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 55102, \\\"account\\\": \\\"acct_2210\\\", \\\"total_cents\\\": 18900, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"paid\\\", \\\"issued\\\": \\\"2026-07-15\\\", \\\"due\\\": \\\"2026-08-14\\\"}\"\n },\n {\n \"id\": \"r-015\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 marketing newsletter draft\",\n \"source\": \"marketing\",\n \"text\": \"Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.\"\n },\n {\n \"id\": \"r-016\",\n \"kind\": \"external_data\",\n \"title\": \"Office move logistics\",\n \"source\": \"internal-ops\",\n \"text\": \"The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.\"\n },\n {\n \"id\": \"r-017\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_4415)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5521\\\", \\\"subject\\\": \\\"July usage dispute\\\", \\\"opened\\\": \\\"2026-08-05\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-2\\\"}]}\"\n },\n {\n \"id\": \"r-018\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_2210)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5502\\\", \\\"subject\\\": \\\"Login issue after SSO migration\\\", \\\"opened\\\": \\\"2026-08-01\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-019\",\n \"kind\": \"external_data\",\n \"title\": \"Vacation and PTO policy\",\n \"source\": \"handbook\",\n \"text\": \"Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.\"\n },\n {\n \"id\": \"r-020\",\n \"kind\": \"external_data\",\n \"title\": \"Runbook: rotating a compromised API key\",\n \"source\": \"ops-wiki\",\n \"text\": \"If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.\"\n },\n {\n \"id\": \"r-021\",\n \"kind\": \"llm_response\",\n \"text\": \"I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.\"\n },\n {\n \"id\": \"r-022\",\n \"kind\": \"external_data\",\n \"title\": \"Customer advisory board Q4 invite draft\",\n \"source\": \"marketing\",\n \"text\": \"Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.\"\n },\n {\n \"id\": \"r-023\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_9902)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_9902\\\", \\\"name\\\": \\\"Colby Fixtures\\\", \\\"plan\\\": \\\"growth\\\", \\\"payment_method\\\": \\\"card_mc_2290\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2026-01-14\\\", \\\"owner\\\": \\\"ops@colbyfixtures.com\\\"}\"\n },\n {\n \"id\": \"r-026\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_5511)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5510\\\", \\\"subject\\\": \\\"Feature request: CSV export for usage analytics\\\", \\\"opened\\\": \\\"2026-08-03\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-027\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 all-hands agenda\",\n \"source\": \"internal-ops\",\n \"text\": \"Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.\"\n },\n {\n \"id\": \"r-029\",\n \"kind\": \"external_data\",\n \"title\": \"Marketing site refresh, visual only\",\n \"source\": \"marketing\",\n \"text\": \"The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.\"\n },\n {\n \"id\": \"r-031\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_6630)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5477\\\", \\\"subject\\\": \\\"Onboarding walkthrough request\\\", \\\"opened\\\": \\\"2026-07-30\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-032\",\n \"kind\": \"external_data\",\n \"title\": \"On-call rotation for September\",\n \"source\": \"internal-ops\",\n \"text\": \"September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.\"\n },\n {\n \"id\": \"r-033\",\n \"kind\": \"external_data\",\n \"title\": \"Partner co-marketing webinar recap\",\n \"source\": \"marketing\",\n \"text\": \"Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.\"\n },\n {\n \"id\": \"r-034\",\n \"kind\": \"external_data\",\n \"title\": \"Conference room booking policy\",\n \"source\": \"handbook\",\n \"text\": \"Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.\"\n },\n {\n \"id\": \"r-035\",\n \"kind\": \"external_data\",\n \"title\": \"Blog editorial calendar, Q4\",\n \"source\": \"marketing\",\n \"text\": \"Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.\"\n },\n {\n \"id\": \"r-036\",\n \"kind\": \"external_data\",\n \"title\": \"Kitchen and supplies restock schedule\",\n \"source\": \"internal-ops\",\n \"text\": \"Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.\"\n }\n ],\n \"task\": {\n \"prompt\": \"What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?\",\n \"tool_name\": \"resolve_billing_dispute\"\n },\n \"budget\": {\n \"max_context_tokens\": 900,\n \"operating_point\": \"np-2026-08-r4\"\n },\n \"render\": true,\n \"render_format\": \"plain\",\n \"return_per_record\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.nextmoca.com/v1/context/select")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"request_id\": \"req-2026-09-03-0001\",\n \"records\": [\n {\n \"id\": \"r-001\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(88231)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 88231, \\\"account\\\": \\\"acct_4415\\\", \\\"total_cents\\\": 432000, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"open\\\", \\\"issued\\\": \\\"2026-07-28\\\", \\\"due\\\": \\\"2026-08-27\\\", \\\"line_items\\\": [{\\\"sku\\\": \\\"NP-USAGE\\\", \\\"desc\\\": \\\"Metered input tokens, July\\\", \\\"qty\\\": 4800000, \\\"unit_price_cents\\\": 0.009}, {\\\"sku\\\": \\\"NP-SUPPORT\\\", \\\"desc\\\": \\\"Priority support\\\", \\\"qty\\\": 1, \\\"unit_price_cents\\\": 49900}]}\"\n },\n {\n \"id\": \"r-002\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_4415)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"name\\\": \\\"Meridian Analytics\\\", \\\"plan\\\": \\\"scale\\\", \\\"payment_method\\\": \\\"card_visa_6411\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2025-11-03\\\", \\\"owner\\\": \\\"dana@meridiananalytics.com\\\"}\"\n },\n {\n \"id\": \"r-003\",\n \"kind\": \"external_data\",\n \"title\": \"Data retention policy v3\",\n \"source\": \"handbook\",\n \"text\": \"Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility.\"\n },\n {\n \"id\": \"r-004\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 2\",\n \"source\": \"handbook\",\n \"text\": \"Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.\"\n },\n {\n \"id\": \"r-005\",\n \"kind\": \"external_data\",\n \"title\": \"Refund policy v4, section 3 (exceptions)\",\n \"source\": \"handbook\",\n \"text\": \"Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.\"\n },\n {\n \"id\": \"r-006\",\n \"kind\": \"tool_result\",\n \"title\": \"get_usage(acct_4415, july)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_4415\\\", \\\"period\\\": \\\"2026-07\\\", \\\"input_tokens\\\": 4800000, \\\"requests\\\": 1210, \\\"stand_downs\\\": 34, \\\"charged_tokens\\\": 4646000}\"\n },\n {\n \"id\": \"r-007\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_9902)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5488\\\", \\\"subject\\\": \\\"API key rotation question\\\", \\\"opened\\\": \\\"2026-08-02\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-008\",\n \"kind\": \"user_input\",\n \"title\": null,\n \"source\": null,\n \"text\": \"Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?\"\n },\n {\n \"id\": \"r-009\",\n \"kind\": \"external_data\",\n \"title\": \"Credit policy v2\",\n \"source\": \"handbook\",\n \"text\": \"Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause.\"\n },\n {\n \"id\": \"r-012\",\n \"kind\": \"tool_result\",\n \"title\": \"get_key_traffic(acct_4415, 2026-07-01..2026-07-19)\",\n \"source\": \"metering-api\",\n \"text\": \"{\\\"keys\\\": [{\\\"key_id\\\": \\\"np_key_a1\\\", \\\"requests\\\": 980, \\\"user_agent\\\": \\\"meridian-batch/2.1\\\", \\\"tokens\\\": 3100000}, {\\\"key_id\\\": \\\"np_key_b2\\\", \\\"requests\\\": 230, \\\"user_agent\\\": \\\"meridian-app/1.4\\\", \\\"tokens\\\": 1700000}], \\\"note\\\": \\\"np_key_a1 traffic stops 2026-07-19T14:02Z\\\"}\"\n },\n {\n \"id\": \"r-013\",\n \"kind\": \"external_data\",\n \"title\": \"Q2 headcount planning notes\",\n \"source\": \"internal-ops\",\n \"text\": \"The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3.\"\n },\n {\n \"id\": \"r-014\",\n \"kind\": \"tool_result\",\n \"title\": \"get_invoice(55102)\",\n \"source\": \"billing-api\",\n \"text\": \"{\\\"invoice_id\\\": 55102, \\\"account\\\": \\\"acct_2210\\\", \\\"total_cents\\\": 18900, \\\"currency\\\": \\\"usd\\\", \\\"status\\\": \\\"paid\\\", \\\"issued\\\": \\\"2026-07-15\\\", \\\"due\\\": \\\"2026-08-14\\\"}\"\n },\n {\n \"id\": \"r-015\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 marketing newsletter draft\",\n \"source\": \"marketing\",\n \"text\": \"Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September.\"\n },\n {\n \"id\": \"r-016\",\n \"kind\": \"external_data\",\n \"title\": \"Office move logistics\",\n \"source\": \"internal-ops\",\n \"text\": \"The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes.\"\n },\n {\n \"id\": \"r-017\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_4415)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5521\\\", \\\"subject\\\": \\\"July usage dispute\\\", \\\"opened\\\": \\\"2026-08-05\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-2\\\"}]}\"\n },\n {\n \"id\": \"r-018\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_2210)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5502\\\", \\\"subject\\\": \\\"Login issue after SSO migration\\\", \\\"opened\\\": \\\"2026-08-01\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-019\",\n \"kind\": \"external_data\",\n \"title\": \"Vacation and PTO policy\",\n \"source\": \"handbook\",\n \"text\": \"Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect.\"\n },\n {\n \"id\": \"r-020\",\n \"kind\": \"external_data\",\n \"title\": \"Runbook: rotating a compromised API key\",\n \"source\": \"ops-wiki\",\n \"text\": \"If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes.\"\n },\n {\n \"id\": \"r-021\",\n \"kind\": \"llm_response\",\n \"text\": \"I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.\"\n },\n {\n \"id\": \"r-022\",\n \"kind\": \"external_data\",\n \"title\": \"Customer advisory board Q4 invite draft\",\n \"source\": \"marketing\",\n \"text\": \"Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support.\"\n },\n {\n \"id\": \"r-023\",\n \"kind\": \"tool_result\",\n \"title\": \"get_account(acct_9902)\",\n \"source\": \"crm-api\",\n \"text\": \"{\\\"account_id\\\": \\\"acct_9902\\\", \\\"name\\\": \\\"Colby Fixtures\\\", \\\"plan\\\": \\\"growth\\\", \\\"payment_method\\\": \\\"card_mc_2290\\\", \\\"delinquent\\\": false, \\\"since\\\": \\\"2026-01-14\\\", \\\"owner\\\": \\\"ops@colbyfixtures.com\\\"}\"\n },\n {\n \"id\": \"r-026\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_5511)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5510\\\", \\\"subject\\\": \\\"Feature request: CSV export for usage analytics\\\", \\\"opened\\\": \\\"2026-08-03\\\", \\\"status\\\": \\\"open\\\", \\\"assignee\\\": \\\"support-lead-1\\\"}]}\"\n },\n {\n \"id\": \"r-027\",\n \"kind\": \"external_data\",\n \"title\": \"Q3 all-hands agenda\",\n \"source\": \"internal-ops\",\n \"text\": \"Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live.\"\n },\n {\n \"id\": \"r-029\",\n \"kind\": \"external_data\",\n \"title\": \"Marketing site refresh, visual only\",\n \"source\": \"marketing\",\n \"text\": \"The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only.\"\n },\n {\n \"id\": \"r-031\",\n \"kind\": \"tool_result\",\n \"title\": \"get_open_tickets(acct_6630)\",\n \"source\": \"support-api\",\n \"text\": \"{\\\"tickets\\\": [{\\\"id\\\": \\\"T-5477\\\", \\\"subject\\\": \\\"Onboarding walkthrough request\\\", \\\"opened\\\": \\\"2026-07-30\\\", \\\"status\\\": \\\"closed\\\", \\\"assignee\\\": \\\"support-lead-3\\\"}]}\"\n },\n {\n \"id\": \"r-032\",\n \"kind\": \"external_data\",\n \"title\": \"On-call rotation for September\",\n \"source\": \"internal-ops\",\n \"text\": \"September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead.\"\n },\n {\n \"id\": \"r-033\",\n \"kind\": \"external_data\",\n \"title\": \"Partner co-marketing webinar recap\",\n \"source\": \"marketing\",\n \"text\": \"Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week.\"\n },\n {\n \"id\": \"r-034\",\n \"kind\": \"external_data\",\n \"title\": \"Conference room booking policy\",\n \"source\": \"handbook\",\n \"text\": \"Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing.\"\n },\n {\n \"id\": \"r-035\",\n \"kind\": \"external_data\",\n \"title\": \"Blog editorial calendar, Q4\",\n \"source\": \"marketing\",\n \"text\": \"Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication.\"\n },\n {\n \"id\": \"r-036\",\n \"kind\": \"external_data\",\n \"title\": \"Kitchen and supplies restock schedule\",\n \"source\": \"internal-ops\",\n \"text\": \"Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week.\"\n }\n ],\n \"task\": {\n \"prompt\": \"What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?\",\n \"tool_name\": \"resolve_billing_dispute\"\n },\n \"budget\": {\n \"max_context_tokens\": 900,\n \"operating_point\": \"np-2026-08-r4\"\n },\n \"render\": true,\n \"render_format\": \"plain\",\n \"return_per_record\": true\n}"
response = http.request(request)
puts response.read_body{
"request_id": "req-2026-09-03-0001",
"rendered_context": "Relevant State\n\n1. Credit policy v2 (handbook)\nService credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method.\nCredits require the account owner's written acknowledgement of the cause.\n\n2. user_input\nCustomer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?\n\n3. Refund policy v4, section 3 (exceptions) (handbook)\nException: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.\n\n4. Refund policy v4, section 2 (handbook)\nRefunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.\n\n5. llm_response\nI've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.",
"policy_version": "np-2026-08-r4",
"selected": [
{
"record_id": "r-009",
"kind": "external_data",
"title": "Credit policy v2",
"source": "handbook",
"score": 32.658829095499584,
"reason": "hard context: answer-bearing evidence: keyword overlap",
"excerpt": "Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method.\nCredits require the account owner's written acknowledgement of the cause.",
"excerpt_format": "plain",
"selected_tokens": 76
},
{
"record_id": "r-008",
"kind": "user_input",
"title": null,
"source": null,
"score": 54.106697605930485,
"reason": "hard context: weighted evidence coverage: current request; keyword overlap; semantic tag overlap",
"excerpt": "Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?",
"excerpt_format": "plain",
"selected_tokens": 60
},
{
"record_id": "r-005",
"kind": "external_data",
"title": "Refund policy v4, section 3 (exceptions)",
"source": "handbook",
"score": 13.458636537340059,
"reason": "hard context: weighted evidence coverage: keyword overlap",
"excerpt": "Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered.",
"excerpt_format": "plain",
"selected_tokens": 67
},
{
"record_id": "r-004",
"kind": "external_data",
"title": "Refund policy v4, section 2",
"source": "handbook",
"score": 14.01558939758398,
"reason": "hard context: recent relevant result: keyword overlap",
"excerpt": "Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible.",
"excerpt_format": "plain",
"selected_tokens": 74
},
{
"record_id": "r-021",
"kind": "llm_response",
"title": null,
"source": null,
"score": 14.644259731672935,
"reason": "soft context: keyword overlap",
"excerpt": "I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown.",
"excerpt_format": "plain",
"selected_tokens": 37
}
],
"tokens_before": 1775,
"tokens_after": 314,
"tokens_saved": 1461,
"records_available": 30,
"records_selected": 5,
"fallback_used": false,
"selection_error": null,
"engine_latency_ms": 7.534137000220653,
"budget_tokens": 900,
"attempted_budget_tokens": [
900
],
"reduction_ratio": 0.8230985915492958,
"safety": {
"selection_safe": true,
"fallback_required": false,
"fallback_reason": "",
"coverage_score": 1,
"evidence_shape": "exact_anchor_lookup",
"evidence_terms": null,
"repair_reasons": []
},
"gate": {
"engaged": true,
"reason": "engage:delivered_support_complete",
"signals": {
"n_candidates": 21,
"high_drift": false
}
},
"format_metrics": {
"context_format": "plain",
"formatted_context_tokens": 361,
"plain_context_tokens": 361,
"toon_context_tokens": null,
"toon_applied": false,
"whole_context_toon_applied": false,
"structured_toon_excerpts": 0,
"structured_toon_tokens_saved": 0,
"toon_tokens_saved_vs_plain": 0,
"selection_strategy_used": "fast",
"selection_strategy_initial": "fast",
"support_contract_used": "generic",
"adapter_attempt_count": 1,
"semantic_adapter_ids": [
"generic"
],
"semantic_routing_bounds_hit": false,
"semantic_adapter_registry_version": "np-adapters-2026-08-r1",
"semantic_router_version": "np-router-2026-08-r3",
"semantic_normalizer_version": "np-normalizer-2026-08-r1",
"support_contract_resolution_version": "np-support-resolution-2026-08-r3",
"attempted_recall_rungs": [
{
"candidate_limit": 250,
"min_selection_score": 8,
"max_selected_records": 18,
"max_selected_tokens": 900
}
]
},
"selection_strategy_used": "fast",
"support_contract_used": "generic",
"adapter_attempt_count": 1,
"usage": {
"meter_version": "npm-2026-08-r1",
"outcome": "engaged",
"input_tokens": 1998,
"charge_multiplier": "1.0",
"price_version": "npp-2026-08-r1",
"currency": "USD"
},
"outcome": "engaged",
"records_submitted": 30,
"records_admitted": 30,
"candidates_truncated": false,
"selection_recall": {
"version": "npsr-2026-08-r2",
"operating_point": "np-2026-08-r4",
"records_submitted": 30,
"records_admitted": 30,
"candidate_matches_total": 21,
"candidates_scored": 21,
"candidates_above_floor": 5,
"records_selected": 5,
"candidate_limit_hit": false,
"weighted_term_coverage": 0.4838709677419355,
"excerpt_term_coverage": 0.44086021505376344,
"rejection_counts": {
"hard_entity_conflict": 0,
"secret_payload": 0,
"below_selection_floor": 16,
"record_count_budget": 0,
"token_budget": 0,
"excerpt_coverage_loss": 0
},
"evidence_confidence_score": 1,
"lexical_coverage": 0.44086021505376344
},
"task_kind": "pointed"
}Authorizations
Authorization: Bearer np_live_…
One credential form. There is no query-parameter, cookie or
x-api-key alternative. The legacy x-api-key header stopped being
accepted at the Bearer cutover and now fails authorization.
Keys are org-scoped, never user-scoped, and the secret is shown exactly once at mint. Rotation is create-then-revoke.
Body
Either ContextRequest (typed records[]) or
SimpleTextContextRequest (free-form text); never both. Maximum
body size is 6 MB, the AWS Lambda synchronous payload cap. API
Gateway rejects an oversized body before the service is invoked, so
guard it client-side rather than relying on a readable error.
- Option 1
- Option 2
The records Needlepath may keep, drop or excerpt. An empty array is accepted and yields an empty selection. Record order breaks score ties, and record count is capped per request alongside the token ceiling. See Limits and Records and tasks.
Show child attributes
Show child attributes
[
{
"id": "r-001",
"kind": "tool_result",
"title": "get_invoice(88231)",
"source": "billing-api",
"text": "{\"invoice_id\": 88231, \"account\": \"acct_4415\", \"total_cents\": 432000, \"currency\": \"usd\", \"status\": \"open\", \"issued\": \"2026-07-28\", \"due\": \"2026-08-27\", \"line_items\": [{\"sku\": \"NP-USAGE\", \"desc\": \"Metered input tokens, July\", \"qty\": 4800000, \"unit_price_cents\": 0.009}, {\"sku\": \"NP-SUPPORT\", \"desc\": \"Priority support\", \"qty\": 1, \"unit_price_cents\": 49900}]}"
},
{
"id": "r-002",
"kind": "tool_result",
"title": "get_account(acct_4415)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_4415\", \"name\": \"Meridian Analytics\", \"plan\": \"scale\", \"payment_method\": \"card_visa_6411\", \"delinquent\": false, \"since\": \"2025-11-03\", \"owner\": \"dana@meridiananalytics.com\"}"
},
{
"id": "r-003",
"kind": "external_data",
"title": "Data retention policy v3",
"source": "handbook",
"text": "Customer-supplied records are retained for 30 days after a support ticket closes, then purged. Internal audit logs of access to those records are retained for one year. This policy governs storage, not billing, and has no bearing on refund or credit eligibility."
},
{
"id": "r-004",
"kind": "external_data",
"title": "Refund policy v4, section 2",
"source": "handbook",
"text": "Refunds for metered usage are issued only for platform-caused overcharges verified against receipts. Refunds for subscription line items are prorated to the day of cancellation. All refunds return to the original payment method within 10 business days. Invoices older than 90 days are not eligible."
},
{
"id": "r-005",
"kind": "external_data",
"title": "Refund policy v4, section 3 (exceptions)",
"source": "handbook",
"text": "Exception: accounts in good standing for over 12 months may receive a one-time courtesy refund of up to $500 per calendar year at a support lead's discretion. This exception does not apply to open invoices; the invoice must be paid before a courtesy refund is considered."
},
{
"id": "r-006",
"kind": "tool_result",
"title": "get_usage(acct_4415, july)",
"source": "metering-api",
"text": "{\"account_id\": \"acct_4415\", \"period\": \"2026-07\", \"input_tokens\": 4800000, \"requests\": 1210, \"stand_downs\": 34, \"charged_tokens\": 4646000}"
},
{
"id": "r-007",
"kind": "tool_result",
"title": "get_open_tickets(acct_9902)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5488\", \"subject\": \"API key rotation question\", \"opened\": \"2026-08-02\", \"status\": \"closed\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-008",
"kind": "user_input",
"title": null,
"source": null,
"text": "Customer (dana@meridiananalytics.com) writes: We were charged $4,320 for July but we believe roughly a third of that usage came from a runaway integration on our side that we shut down on July 19. Can we get a refund or credit for the excess?"
},
{
"id": "r-009",
"kind": "external_data",
"title": "Credit policy v2",
"source": "handbook",
"text": "Service credits differ from refunds: credits may be granted for customer-caused overuse at up to 25% of the disputed amount, once per account per year, and are applied to the next invoice rather than returned to the payment method. Credits require the account owner's written acknowledgement of the cause."
},
{
"id": "r-012",
"kind": "tool_result",
"title": "get_key_traffic(acct_4415, 2026-07-01..2026-07-19)",
"source": "metering-api",
"text": "{\"keys\": [{\"key_id\": \"np_key_a1\", \"requests\": 980, \"user_agent\": \"meridian-batch/2.1\", \"tokens\": 3100000}, {\"key_id\": \"np_key_b2\", \"requests\": 230, \"user_agent\": \"meridian-app/1.4\", \"tokens\": 1700000}], \"note\": \"np_key_a1 traffic stops 2026-07-19T14:02Z\"}"
},
{
"id": "r-013",
"kind": "external_data",
"title": "Q2 headcount planning notes",
"source": "internal-ops",
"text": "The Q2 headcount review covered open requisitions across support and account management. Two backfills were approved pending final budget sign-off from finance; the rest carry into Q3."
},
{
"id": "r-014",
"kind": "tool_result",
"title": "get_invoice(55102)",
"source": "billing-api",
"text": "{\"invoice_id\": 55102, \"account\": \"acct_2210\", \"total_cents\": 18900, \"currency\": \"usd\", \"status\": \"paid\", \"issued\": \"2026-07-15\", \"due\": \"2026-08-14\"}"
},
{
"id": "r-015",
"kind": "external_data",
"title": "Q3 marketing newsletter draft",
"source": "marketing",
"text": "Meridian Analytics is one of several accounts featured in our upcoming case-study series. The draft highlights their 40% pipeline acceleration after adopting the platform. Publication is scheduled for September."
},
{
"id": "r-016",
"kind": "external_data",
"title": "Office move logistics",
"source": "internal-ops",
"text": "The Austin office move completes August 15. Badge access transfers automatically. Update your commuter benefits by August 10 if you use transit passes."
},
{
"id": "r-017",
"kind": "tool_result",
"title": "get_open_tickets(acct_4415)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5521\", \"subject\": \"July usage dispute\", \"opened\": \"2026-08-05\", \"status\": \"open\", \"assignee\": \"support-lead-2\"}]}"
},
{
"id": "r-018",
"kind": "tool_result",
"title": "get_open_tickets(acct_2210)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5502\", \"subject\": \"Login issue after SSO migration\", \"opened\": \"2026-08-01\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-019",
"kind": "external_data",
"title": "Vacation and PTO policy",
"source": "handbook",
"text": "Full-time staff accrue 15 days of PTO per year, front-loaded each January. Unused days above a 5-day carryover are paid out at year end. This policy applies to internal staff only and has no customer-facing effect."
},
{
"id": "r-020",
"kind": "external_data",
"title": "Runbook: rotating a compromised API key",
"source": "ops-wiki",
"text": "If a key is suspected compromised: revoke it immediately from the dashboard, mint a replacement, and audit the last 30 days of request logs for the revoked key. Notify the account owner within one business hour. This does not apply to routine billing disputes."
},
{
"id": "r-021",
"kind": "llm_response",
"text": "I've pulled up account acct_4415 and I'm reviewing the July invoice and usage history now. One moment while I check the key-level traffic breakdown."
},
{
"id": "r-022",
"kind": "external_data",
"title": "Customer advisory board Q4 invite draft",
"source": "marketing",
"text": "Draft invitation for the Q4 customer advisory board: eight accounts, half-day session, catered lunch, and a closing networking hour. Invitations go out via the account team, not support."
},
{
"id": "r-023",
"kind": "tool_result",
"title": "get_account(acct_9902)",
"source": "crm-api",
"text": "{\"account_id\": \"acct_9902\", \"name\": \"Colby Fixtures\", \"plan\": \"growth\", \"payment_method\": \"card_mc_2290\", \"delinquent\": false, \"since\": \"2026-01-14\", \"owner\": \"ops@colbyfixtures.com\"}"
},
{
"id": "r-026",
"kind": "tool_result",
"title": "get_open_tickets(acct_5511)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5510\", \"subject\": \"Feature request: CSV export for usage analytics\", \"opened\": \"2026-08-03\", \"status\": \"open\", \"assignee\": \"support-lead-1\"}]}"
},
{
"id": "r-027",
"kind": "external_data",
"title": "Q3 all-hands agenda",
"source": "internal-ops",
"text": "Agenda: Q3 numbers recap, the Austin office move timeline, two customer case studies, and a Q&A. Scheduled for the last Thursday of the quarter, recorded for anyone who cannot attend live."
},
{
"id": "r-029",
"kind": "external_data",
"title": "Marketing site refresh, visual only",
"source": "marketing",
"text": "The marketing homepage and case-study pages move to a refreshed visual design next month. Existing URLs and content are unchanged; this is a styling pass only."
},
{
"id": "r-031",
"kind": "tool_result",
"title": "get_open_tickets(acct_6630)",
"source": "support-api",
"text": "{\"tickets\": [{\"id\": \"T-5477\", \"subject\": \"Onboarding walkthrough request\", \"opened\": \"2026-07-30\", \"status\": \"closed\", \"assignee\": \"support-lead-3\"}]}"
},
{
"id": "r-032",
"kind": "external_data",
"title": "On-call rotation for September",
"source": "internal-ops",
"text": "September on-call: week 1 support-lead-1, week 2 support-lead-2, week 3 support-lead-3, week 4 support-lead-1. Swap requests go through the usual calendar invite at least 48 hours ahead."
},
{
"id": "r-033",
"kind": "external_data",
"title": "Partner co-marketing webinar recap",
"source": "marketing",
"text": "Tuesday's co-marketing webinar drew 140 live attendees, with a recording queued for the newsletter. Follow-up survey responses are due back from the partner team by end of week."
},
{
"id": "r-034",
"kind": "external_data",
"title": "Conference room booking policy",
"source": "handbook",
"text": "Rooms can be held up to 90 days ahead through the office system. No-shows for two consecutive bookings lose booking privileges for 30 days. This policy is unrelated to customer accounts or billing."
},
{
"id": "r-035",
"kind": "external_data",
"title": "Blog editorial calendar, Q4",
"source": "marketing",
"text": "Q4 blog calendar: a launch recap in week 1, two customer spotlights in weeks 3 and 6, and a year-in-review post closing out the quarter. Drafts are due to editorial ten business days before publication."
},
{
"id": "r-036",
"kind": "external_data",
"title": "Kitchen and supplies restock schedule",
"source": "internal-ops",
"text": "Snack and coffee restocks happen every Monday and Thursday. Submit special requests through the office system by end of day Friday for the following week."
}
]
The query the selected context has to serve.
Show child attributes
Show child attributes
{
"prompt": "What does the evidence show about invoice 88231: is the disputed usage customer-caused, and does it qualify for a refund or a service credit?",
"tool_name": "resolve_billing_dispute"
}
The operating point, in arm-neutral quantities only. No method-tuning
knobs appear here or anywhere else in the request: thresholds,
weightings, tier rules and gate parameters resolve server-side from the
operating_point label.
Show child attributes
Show child attributes
{
"max_context_tokens": 900,
"operating_point": "np-2026-08-r4"
}
Your correlation id, echoed back byte-for-byte. Optional:
it is sent-side only, a caller correlation id we never require;
absent is echoed back as "". When sent, keep it to ≤ 128
characters of [A-Za-z0-9._:-], and put no record content,
customer text or credentials in it, because it reaches our logs. See
Retention and trust.
"req-2026-09-03-0001"
Ask for rendered_context, a model-facing string assembled from the
selection. render has no effect; rendered_context is always
returned. Ignore it client-side if unwanted.
true
plain leaves excerpts as text. hybrid additionally permits a
structured excerpt to be re-encoded into a more compact form, and
excerpt_format reports which form was used.
Send plain if you re-parse excerpts as JSON.
plain, hybrid "plain"
Include the selected[] per-record detail: score, reason, excerpt
and token count. Set false for rendered_context plus the token
arithmetic only, which is a materially smaller response body.
true
Response
A selection. Includes stand-downs and engine-internal failures,
so read fallback_used and selection_error. This service returns 200
with a usable body rather than a 5xx when its own selection pass
fails, because the correct client behaviour in that case is to send
the original context, which the body already contains.
The selection.
Required by the contract (the published client raises if any is
missing, or if request_id does not echo): request_id,
rendered_context, tokens_before, tokens_after, tokens_saved,
records_available, records_selected, fallback_used, outcome,
engine_latency_ms.
Everything else is optional and new optional fields ship within
/v1, so ignore what you do not recognise.
This object is open, and it already carries keys this schema does not
list. Some are operating-point specific, so the exact set varies with
the operating_point you send. A generated client must tolerate unknown
keys rather than reject or drop the response: validate the required
fields above and pass the rest through. If your generator defaults
additionalProperties to false, it will produce a client that current
responses already fail.
Your request_id, echoed byte-for-byte.
The model-facing block, assembled from the selection. Always returned.
The engine's own accounting of the context available before
filtering. It is not the billing quantity: the meter also counts
record.title, task.prompt and task.recent_prompts, so
usage.input_tokens is the larger number. Budget against this, do
not reconcile an invoice with it. See How to recompute your own
bill.
Context size after selection, on the same engine-internal basis as tokens_before.
tokens_before - tokens_after. Zero on a stand-down, which is a correct outcome rather than a failed one.
How many records the engine considered.
How many it selected.
How the engine resolved this request, at the top level so that you never have to read a nested object to find it.
An open enum. Do not exhaustively match it, and do not fail closed on a value you do not recognise: new outcomes ship additively within /v1. Current values are engaged (records were selected), escalated (the engine declined to select because the eligible full context exceeded the capacity it had to fit inside, so selected is empty and rendered_context is an empty string) and stood_down (the engine chose not to act).
This is not the same field as usage.outcome, and the two can legitimately disagree on a single response. This field reports what the engine did. usage.outcome reports how the request was priced, and it resolves selection failures first, so a response can carry outcome: "engaged" alongside usage.outcome: "fallback". Read this field to decide what to do with the response; read usage.outcome to explain a charge.
escalated is charged at the full rate and returns no context. Treat it as "use the context you already had". It is not an error, and it is not a saving.
"engaged"
"escalated"
"stood_down"
The engine stood aside and returned your context essentially intact.
It does not tell you why: a stand-down, an empty record set and an
engine-internal exception all produce it. Read outcome first, then
selection_error and format_metrics.engine_fallback_reason to tell
the last two apart. Do not read gate for this: it is the envelope
gate's shadow assessment and can disagree with outcome.
See Errors.
Server-measured selection time, excluding network transit, so it is not your round trip. Example values in this document are illustrative and are not a performance commitment.
The frozen version behind the operating_point that actually ran.
Record it with every result: it is how you detect that you inherited
a default you did not choose.
Per-record detail, in selection order. Empty when you sent
return_per_record: false and also empty on some stand-downs, so
read records_selected rather than the array length.
Show child attributes
Show child attributes
How many extra candidates budget.autochunk produced: the candidate
count minus the number of records you sent. Present only on requests
that set budget.autochunk, and absent -- not zero -- on every other
request, so that its absence cannot be read as "autochunk ran and split
nothing".
Set when the engine's own selection pass raised. The HTTP status is still 200 and the body carries a usable full-context result. Alarm on this field, not on 5xx.
The budget the returned selection was produced under.
Every rung attempted on the adaptive ladder, in order. Empty on the fixed path. Watch it to see whether an adaptive workload is doing several selection passes per request.
tokens_saved / tokens_before, on the engine-internal basis. Zero when tokens_before is zero.
Present only when a coverage verdict ran, and null on the
fixed-budget path. A null safety means no verdict was computed,
never that the verdict was fine.
Show child attributes
Show child attributes
Present when a gate decision was made.
Show child attributes
Show child attributes
Free-form, additive rendering and diagnostic telemetry. Treat unknown keys as informational. Keys you may see:
engine_fallback_reason: present only when the engine stood aside, carrying its own reason.request_id_sanitized: true: yourrequest_idbroke the length or charset bound and the internal copy was truncated. Your echo is still your bytes.client_latency_ms: added by the published client, not by the server.
The metering receipt for this request. See How billing works.
Show child attributes
Show child attributes