{
  "openapi": "3.1.0",
  "info": {
    "title": "Surplus Intelligence Inference API",
    "description": "OpenAI-compatible inference marketplace with x402 pay-per-request access on Base.",
    "version": "3.1.0",
    "contact": {
      "name": "Surplus Intelligence",
      "url": "https://www.surplusintelligence.ai"
    },
    "x-guidance": "For x402 pay-per-request inference, POST to /x402/api/inference/v1/chat/completions without Authorization. Prefer accepts[].find(a => a.scheme === \"upto\") and use exact only as fallback. Sign the chosen payment requirement, include base64(JSON.stringify(paymentPayload)) in PAYMENT-SIGNATURE, and resend the same body. Successful paid responses return HTTP 200, PAYMENT-RESPONSE, and an OpenAI-compatible completion body. When using @x402/evm with viem, pass a signer object with explicit address; do not rely on walletClient.address if undefined."
  },
  "servers": [
    {
      "url": "https://www.surplusintelligence.ai",
      "description": "Production"
    },
    {
      "url": "http://localhost:3000",
      "description": "Local development"
    }
  ],
  "paths": {
    "/x402/api/inference/v1/chat/completions": {
      "post": {
        "summary": "Create chat completion (x402)",
        "description": "OpenAI-compatible chat completions with x402 payment. Returns 402 with payment requirements for unauthenticated requests. Sign and attach payment to proceed.",
        "operationId": "x402CreateChatCompletion",
        "x-payment-info": {
          "protocols": [
            "x402"
          ],
          "authMode": "paid",
          "price": {
            "mode": "dynamic",
            "currency": "USD",
            "min": "0.001",
            "max": "1.00"
          }
        },
        "security": [
          {
            "x402Payment": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion response",
            "headers": {
              "PAYMENT-RESPONSE": {
                "description": "Base64-encoded x402 settlement response.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "402": {
            "description": "Payment required. Returns x402 v2 payment requirements.",
            "headers": {
              "PAYMENT-REQUIRED": {
                "description": "Base64-encoded x402 v2 payment requirements.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequiredResponse"
                }
              }
            }
          }
        },
        "x-agent-instructions": {
          "preferredScheme": "upto",
          "fallbackScheme": "exact",
          "endpoint": "https://www.surplusintelligence.ai/x402/api/inference/v1/chat/completions",
          "steps": [
            "POST the OpenAI-compatible request body without Authorization.",
            "Decode PAYMENT-REQUIRED as base64 JSON.",
            "Select accepts.find(a => a.scheme === \"upto\") when present.",
            "Create an x402 payment payload for the selected requirement.",
            "Retry the identical request with PAYMENT-SIGNATURE set to base64(JSON.stringify(paymentPayload)).",
            "Expect HTTP 200, PAYMENT-RESPONSE, and an OpenAI-compatible response body."
          ],
          "viemSignerNote": "@x402/evm UptoEvmScheme needs a signer with explicit address. If using viem, build { address: account.address, signTypedData: account.signTypedData, readContract, getTransactionCount, estimateFeesPerGas } rather than relying on walletClient.address."
        }
      }
    },
    "/x402/api/inference/v1/completions": {
      "post": {
        "summary": "Create completion (x402)",
        "description": "OpenAI-compatible legacy completions with x402 payment. Same payment flow as chat completions.",
        "operationId": "x402CreateCompletion",
        "x-payment-info": {
          "protocols": [
            "x402"
          ],
          "authMode": "paid",
          "price": {
            "mode": "dynamic",
            "currency": "USD",
            "min": "0.001",
            "max": "1.00"
          }
        },
        "security": [
          {
            "x402Payment": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion response",
            "headers": {
              "PAYMENT-RESPONSE": {
                "description": "Base64-encoded x402 settlement response.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "402": {
            "description": "Payment required.",
            "headers": {
              "PAYMENT-REQUIRED": {
                "description": "Base64-encoded x402 v2 payment requirements.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequiredResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/inference/v1/models": {
      "get": {
        "summary": "List available models",
        "description": "Returns OpenAI-compatible model metadata with current Surplus Intelligence marketplace pricing. Free, no payment required.",
        "operationId": "listModels",
        "x-payment-info": {
          "authMode": "free"
        },
        "responses": {
          "200": {
            "description": "Model list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "example": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Model"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/inference/v1/prices": {
      "get": {
        "summary": "List current prices",
        "description": "Returns current model prices for the inference marketplace. Free, no payment required.",
        "operationId": "listPrices",
        "x-payment-info": {
          "authMode": "free"
        },
        "responses": {
          "200": {
            "description": "Price list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/inference/v1/chat/completions": {
      "post": {
        "summary": "Create chat completion (canonical)",
        "description": "OpenAI-compatible chat completions. Requires valid request body. For x402 probes, use /x402/api/inference/v1/chat/completions instead.",
        "operationId": "createChatCompletion",
        "x-payment-info": {
          "protocols": [
            "x402"
          ],
          "authMode": "paid",
          "price": {
            "mode": "dynamic",
            "currency": "USD",
            "min": "0.001",
            "max": "1.00"
          }
        },
        "security": [
          {
            "bearerAuth": []
          },
          {
            "x402Payment": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion response",
            "headers": {
              "PAYMENT-RESPONSE": {
                "description": "Base64-encoded x402 settlement response when paid via x402.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "402": {
            "description": "Payment required.",
            "headers": {
              "PAYMENT-REQUIRED": {
                "description": "Base64-encoded x402 v2 payment requirements.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequiredResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/inference/v1/completions": {
      "post": {
        "summary": "Create completion (canonical)",
        "description": "OpenAI-compatible legacy completions. For x402 probes, use /x402/api/inference/v1/completions instead.",
        "operationId": "createCompletion",
        "x-payment-info": {
          "protocols": [
            "x402"
          ],
          "authMode": "paid",
          "price": {
            "mode": "dynamic",
            "currency": "USD",
            "min": "0.001",
            "max": "1.00"
          }
        },
        "security": [
          {
            "bearerAuth": []
          },
          {
            "x402Payment": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion response",
            "headers": {
              "PAYMENT-RESPONSE": {
                "description": "Base64-encoded x402 settlement response when paid via x402.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "402": {
            "description": "Payment required.",
            "headers": {
              "PAYMENT-REQUIRED": {
                "description": "Base64-encoded x402 v2 payment requirements.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequiredResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/x402/info": {
      "get": {
        "summary": "Get x402 inference information",
        "description": "Returns agent-facing metadata for Surplus Intelligence x402 pay-per-request inference endpoints. Free, no payment required.",
        "operationId": "getX402Info",
        "x-payment-info": {
          "authMode": "free"
        },
        "responses": {
          "200": {
            "description": "x402 inference metadata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/X402InfoResponse"
                }
              }
            }
          }
        }
      }
    },
    "/x402/api/inference/v1/models": {
      "get": {
        "summary": "List available models (x402 prefix)",
        "description": "Proxied model listing under the x402 path prefix. Same response as /api/inference/v1/models. Free, no payment required.",
        "operationId": "x402ListModels",
        "x-payment-info": {
          "authMode": "free"
        },
        "responses": {
          "200": {
            "description": "Model list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/x402/api/twitter/v2/tweets/search/recent": {
      "get": {
        "summary": "Twitter recent search",
        "description": "Search recent X/Twitter posts via read-only seller-supplied Twitter API capacity and x402 payment.",
        "operationId": "twitter_recent_search",
        "security": [
          {
            "x402Payment": []
          }
        ],
        "x-agentic-market-endpoint": true,
        "x-x402": {
          "version": 2,
          "supportedSchemes": [
            "upto",
            "exact"
          ],
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "pricing": "dynamic"
        },
        "responses": {
          "200": {
            "description": "Paid upstream response"
          },
          "402": {
            "description": "x402 Payment Required challenge"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/x402/api/twitter/v2/users/by/username/{username}": {
      "get": {
        "summary": "Twitter user lookup",
        "description": "Look up an X/Twitter user by username via read-only seller-supplied Twitter API capacity and x402 payment.",
        "operationId": "twitter_user_lookup",
        "security": [
          {
            "x402Payment": []
          }
        ],
        "x-agentic-market-endpoint": true,
        "x-x402": {
          "version": 2,
          "supportedSchemes": [
            "upto",
            "exact"
          ],
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "pricing": "dynamic"
        },
        "responses": {
          "200": {
            "description": "Paid upstream response"
          },
          "402": {
            "description": "x402 Payment Required challenge"
          },
          "502": {
            "description": "Upstream provider error"
          }
        },
        "parameters": [
          {
            "name": "username",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/x402/api/venice/crypto/rpc/{network}": {
      "post": {
        "summary": "Venice crypto RPC",
        "description": "Proxy JSON-RPC 2.0 requests to Venice crypto RPC networks via seller-supplied Venice API capacity and x402 payment.",
        "operationId": "venice_crypto_rpc",
        "security": [
          {
            "x402Payment": []
          }
        ],
        "x-agentic-market-endpoint": true,
        "x-x402": {
          "version": 2,
          "supportedSchemes": [
            "upto",
            "exact"
          ],
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "pricing": "dynamic"
        },
        "responses": {
          "200": {
            "description": "Paid upstream response"
          },
          "402": {
            "description": "x402 Payment Required challenge"
          },
          "502": {
            "description": "Upstream provider error"
          }
        },
        "parameters": [
          {
            "name": "network",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "base-mainnet"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object"
                  },
                  {
                    "type": "array",
                    "maxItems": 100
                  }
                ]
              },
              "example": {
                "jsonrpc": "2.0",
                "method": "eth_chainId",
                "params": [],
                "id": 1
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Model": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "llama-3.3-70b"
          },
          "object": {
            "type": "string",
            "example": "model"
          },
          "created": {
            "type": "integer"
          },
          "owned_by": {
            "type": "string",
            "example": "surplus-intelligence"
          }
        }
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "example": "llama-3.3-70b"
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "system",
                    "user",
                    "assistant",
                    "tool"
                  ]
                },
                "content": {
                  "type": "string"
                }
              }
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "stream": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "CompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string",
            "example": "llama-3.3-70b"
          },
          "prompt": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "stream": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "PaymentRequiredResponse": {
        "type": "object",
        "properties": {
          "x402Version": {
            "type": "integer",
            "example": 2
          },
          "accepts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PaymentRequirement"
            }
          },
          "resource": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "mimeType": {
                "type": "string",
                "example": "application/json"
              }
            }
          }
        }
      },
      "PaymentRequirement": {
        "type": "object",
        "properties": {
          "scheme": {
            "type": "string",
            "enum": [
              "upto",
              "exact"
            ]
          },
          "network": {
            "type": "string",
            "example": "eip155:8453"
          },
          "asset": {
            "type": "string",
            "example": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
          },
          "amount": {
            "type": "string",
            "description": "USDC micro-units."
          },
          "payTo": {
            "type": "string"
          },
          "maxTimeoutSeconds": {
            "type": "integer"
          },
          "extra": {
            "type": "object"
          }
        }
      },
      "X402InfoResponse": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "example": "Surplus Intelligence x402 Inference API"
          },
          "version": {
            "type": "string",
            "example": "3.1.0"
          },
          "description": {
            "type": "string"
          },
          "x402": {
            "type": "object"
          },
          "inference": {
            "type": "object"
          },
          "discovery": {
            "type": "object"
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Surplus Intelligence buyer API key."
      },
      "x402Payment": {
        "type": "apiKey",
        "in": "header",
        "name": "PAYMENT-SIGNATURE",
        "description": "Base64-encoded x402 v2 payment payload."
      }
    }
  },
  "x-x402": {
    "version": 2,
    "discovery": "/.well-known/x402",
    "facilitator": "https://api.cdp.coinbase.com/platform/v2/x402",
    "supportedSchemes": [
      "upto",
      "exact"
    ],
    "preferredScheme": "exact",
    "supportedTokens": [
      "USDC"
    ],
    "network": "eip155:8453",
    "chainId": 8453,
    "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
  }
}
