
OpenAI SDK
Chat Completions and Responses
Set baseURL to the gateway's /v1 and pass your tok_ key as the API key.
Start building
Go from a new project key to a paid request and its signed receipt. The gateway speaks the OpenAI and Anthropic wire protocols, so your existing SDK needs a base URL and a key -- plus one x402 signing step, because every request is quoted and paid on GIWA Sepolia.
https://api.giwa.tokscale.aiEvery gateway request is fenced to an owner-scoped project. Create a project in the console before issuing a key. The key identifies your project; it does not bypass payment or authorize a different project.
Create a projectOpen the project's Connections page and create a tok_ API key. Save it when it is shown because the plaintext key appears exactly once.
Fund the wallet your x402 client will use through Payments. The public gateway quotes each request and accepts only a signature over that quote; it never accepts test-credit headers.
Choose a projectSend the public quote request below. It returns 402 Payment Required and a payment-required header. Your x402 client must sign those exact terms, then replay the byte-identical request with the same Idempotency-Key and its payment-signature. A 202 is still settling: retry the identical request until it returns its terminal result.
export GIWA_GATEWAY_ORIGIN=https://api.giwa.tokscale.ai
export GIWA_API_KEY=tok_replace_with_your_project_key
curl --silent --show-error --include \
"$GIWA_GATEWAY_ORIGIN/v1/chat/completions" \
--header "Authorization: Bearer $GIWA_API_KEY" \
--header "Idempotency-Key: quickstart-001" \
--header "Content-Type: application/json" \
--header "x-giwa-payment-mode: x402" \
--data-binary '{
"model": "claude-haiku-4-5",
"max_tokens": 64,
"messages": [
{ "role": "user", "content": "Reply with exactly: hello." }
]
}'Reuse one Idempotency-Key for every retry of the same request, including the paid replay and any 202 poll. A fresh key is a distinct, separately billable attempt.
Every accepted request settles credit and can produce a signed UsageReceiptV1. Open the project's Requests and Receipts pages to inspect the recorded usage and verify the receipt end to end.
What you get back
These are unedited bytes from a single live GIWA Sepolia journey, not illustrative examples. The unpaid quote answered 402 with the offer below, the signed replay settled through 202 to 200 after 10 attempts under one idempotency key, and the receipt endpoint returned a signed UsageReceiptV1. The offer's giwaApiKeyId is the one omitted field, because it names a credential.
b4efb91c-31b8-5dde-aff9-f1f2c943aca40xf789227bb51a840cac4f55e42a713296d33e1064HTTP/1.1 402 Payment Required
payment-required: <base64> # decoded below
{
"x402Version": 2,
"resource": {
"url": "https://api.giwa.tokscale.ai/v1/chat/completions",
"description": "GIWA Sepolia measured request payment",
"mimeType": "application/json"
},
"accepts": [
{
"scheme": "upto",
"network": "eip155:91342",
"amount": "500",
"payTo": "0xcbacd987b32985ead14e62e6c6f246b724f8c42f",
"maxTimeoutSeconds": 60,
"asset": "0x58d5608e89b5c1c3b96481a199756b1a292061a9",
"extra": {
"assetTransferMethod": "permit2",
"name": "Tokscale Test USD",
"version": "1",
"facilitatorAddress": "0xe773d0a15bf70c524196bdb61cafaf5aef9e43ba",
"giwaBindingVersion": 1,
"giwaBindingDigest": "c48c9a12bc30cf4050db4e9afb953b1549fd8d7e2085d87434700a0b082ad361",
"giwaProjectId": "2fc2e648-6df9-4e5e-95eb-57b6c2b7bab8",
"giwaProtocol": "openai-chat",
"giwaCanonicalRoute": "/v1/chat/completions",
"giwaRequestId": "7f1cb62b-f788-508e-a1fe-94813a99e101",
"giwaRequestFingerprint": "e44cc80c2f4c8f8ef2d7302a3c68d2efa66471acb151c3221a944e76450c49d8",
"giwaExpiresAtUnixSeconds": "1786317350",
"giwaAuthorizationNonce": "104741931581538737052105793164568138009371329182063676829549077208494401108734",
"giwaUptoProxyAddress": "0x4020a4f3b7b90cca423b9fabcc0ce57c6c240002"
}
}
],
"extensions": {}
}Client setup
The gateway speaks the OpenAI and Anthropic wire protocols, so an existing client needs a base URL and a key. Payment is the one thing an SDK cannot do for you: the public lane has no header bypass, so your application adds the x402 signing step from step 4 around the request.

Chat Completions and Responses
Set baseURL to the gateway's /v1 and pass your tok_ key as the API key.

Messages API
Set baseURL to the gateway origin and send exactly one auth header, x-api-key or Bearer.

OpenAI and Anthropic providers
Pass the gateway baseURL to createOpenAI or createAnthropic, then use generateText as usual.

Responses API
Point model_provider at the gateway in config.toml and set env_key to your key variable.

Messages API
Export ANTHROPIC_BASE_URL as the gateway origin and ANTHROPIC_API_KEY as your tok_ key.