Skip to content

Runnable examples

Every example below runs offline against a mock API with no key and no signup. Each one deliberately retries the payment call and exits 0 only if one order came back.

terminal
git clone https://github.com/RulezZzOr/ordercore-examples.git
cd ordercore-examples/agent-commerce-demo && node run.mjs
→ complete_checkout_session → order_1 → complete_checkout_session → order_1 ← the retry, same order ✅ 2 completion calls -> 1 order. Idempotency held.

Pick your stack

Claude (tool use)

Anthropic SDK · claude-opus-5

A complete Claude agentic loop: tool_use → execute → tool_result until done. Offline mode uses a scripted model, so you see the exact wire shapes without an API key.

terminal
cd ordercore-examples/claude-checkout-agent
node run.mjs

OpenAI (function calling)

gpt-4o · chat.completions

The same three tools as OpenAI function definitions, driven by a chat.completions loop. Zero dependencies — raw fetch.

terminal
cd ordercore-examples/openai-checkout-agent
node run.mjs

LangChain / LangGraph

langchain-core · Python 3.8+

Tools as plain @tool functions. Import TOOLS and bind them to any LangChain chat model or LangGraph agent — the loop in the file is just a demonstration.

terminal
cd ordercore-examples/langchain-checkout-agent
python3 run.py

Vercel AI SDK

ai v7 · any provider

AI SDK tool() definitions and one generateText call with stopWhen: stepCountIs(10). Offline mode uses the SDK's own MockLanguageModelV3. Export orderCoreTools into any streamText or useChat route.

terminal
cd ordercore-examples/vercel-ai-checkout-agent
npm i && node run.mjs

MCP server

stdio · macOS/Linux/Windows

No loop code at all: register the ordercore-mcp binary and your client gets 9 commerce tools. Works with Claude Code, Claude Desktop, and Cursor.

terminal
cd ordercore-examples/mcp
claude mcp add ordercore …

Core flow (REST)

no framework · REST

The shortest possible proof: create a checkout session, complete it, complete it again — same order. Node and Python versions.

terminal
cd ordercore-examples/agent-commerce-demo
node run.mjs / python3 run.py

Catalog reads

no framework · REST

The “shop” half: search_products, get_product, get_prices, get_inventory as plain REST GETs.

terminal
cd ordercore-examples/catalog-read
node run.mjs

Idempotency keys

no framework · REST

The other idempotency model: Idempotency-Key on POST /v1/orders — 201 new, 200 replay, 409 conflict.

terminal
cd ordercore-examples/idempotent-orders
node run.mjs

Prove idempotency with no account at all

Every example above runs offline against a mock. If you want the guarantee proved against the real API without signing up, ask for a write sandbox — you get your own isolated tenant, pre-seeded, capped at 25 orders:

R=$(curl -sS -X POST https://api.ordercore.ai/bootstrap/sandbox-key \
  -H 'Content-Type: application/json' -d '{"mode":"write"}')
KEY=$(echo "$R" | jq -r .api_key); SKU=$(echo "$R" | jq -r .sample_sku_id)

BODY='{"idempotency_key":"retry-me","customer_id":"demo-buyer",
       "items":[{"sku_id":"'$SKU'","quantity":1}]}'

# 201 — order created
curl -X POST https://api.ordercore.ai/v1/orders -H "X-API-Key: $KEY" \
  -H 'Content-Type: application/json' -d "$BODY"

# run it again → 200 with the SAME order id. Changed payload → 409.

The response also returns try_next: the same command with your key and SKU already filled in, ready to paste.

The same guarantee holds through a checkout session: open one, complete it, complete it again — the same order comes back. Completing takes no payment (payment_intent_id comes back empty), because …/payment-intent is the one checkout route left out of the grant. Catalog, inventory, webhook and API-key writes all return 403. Full walkthrough: the API guide.

Going live

idempotent-orders, catalog-read and sandbox-quickstart run against the real API on the no-signup sandbox key — just set ORDERCORE_API_KEY. The Claude, OpenAI and Gemini agents can use that key for their commerce calls too, but each also needs its own model key. Only agent-commerce-demo needs a full read/write key: it mints a buyer-facing checkout token, which a sandbox key cannot. Each says so rather than failing on a bare 403. Request a key — two fields, no payment. Confirming the emailed link issues your first read/write key automatically and sends it to you: no manual step, no sales call.

Machine-readable surfaces: OpenAPI 3.1 spec · API guide as markdown · tool schemas for OpenAI/Claude/Gemini

Why the retry matters

An agent retries on a timeout, on a rate limit, when its own loop restarts. If checkout isn't idempotent, that retry is a second order and a second charge on a real person's card. Full write-up: idempotent orders for AI agents.

Get an API key