Skip to main content

Response Format

Every Hypermid API response uses a consistent envelope format. This makes it straightforward to handle responses, errors, and metadata across all endpoints.

Response Envelope

All endpoints return a JSON object with three top-level fields:
{
  "data": <T | null>,
  "error": <ErrorObject | null>,
  "meta": {
    "requestId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "timestamp": 1711234567,
    "rateLimit": {
      "limit": 2000,
      "remaining": 1998,
      "reset": 1711234627
    }
  }
}
FieldTypeDescription
dataT | nullThe response payload. null when an error occurs.
errorErrorObject | nullError details. null on success.
metaMetaObjectRequest metadata, always present.
Exactly one of data or error will be non-null. You can use this as a discriminator in your code.

Success Response

When a request succeeds, data contains the response payload and error is null:
{
  "data": {
    "chains": [
      { "id": 1, "name": "Ethereum", "type": "EVM" },
      { "id": 42161, "name": "Arbitrum", "type": "EVM" }
    ]
  },
  "error": null,
  "meta": {
    "requestId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "timestamp": 1711234567,
    "rateLimit": {
      "limit": 2000,
      "remaining": 1997,
      "reset": 1711234627
    }
  }
}

Error Response

When a request fails, error contains the error details and data is null:
{
  "data": null,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Parameter 'fromChain' is required",
    "details": {
      "field": "fromChain",
      "reason": "missing"
    }
  },
  "meta": {
    "requestId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    "timestamp": 1711234568,
    "rateLimit": {
      "limit": 2000,
      "remaining": 1996,
      "reset": 1711234627
    }
  }
}

Error Object

FieldTypeDescription
codestringMachine-readable error code (e.g., INVALID_PARAMS)
messagestringHuman-readable error description
detailsobjectAdditional context about the error (varies by error type)

Meta Object

The meta object is always present and contains:
FieldTypeDescription
requestIdstringUnique UUID for this request. Include this when contacting support.
timestampnumberUnix timestamp of the response.
rateLimit.limitnumberMaximum requests allowed per minute.
rateLimit.remainingnumberRequests remaining in the current window.
rateLimit.resetnumberUnix timestamp when the rate limit window resets.

Error Codes

CodeHTTP StatusDescription
INVALID_PARAMS400Missing or invalid request parameters
VALIDATION_ERROR400Request body failed validation
SLIPPAGE_ERROR400Slippage tolerance exceeded
UNAUTHORIZED401Invalid or missing API key for a protected endpoint
NO_ROUTE_FOUND404No swap route found for the given parameters
RATE_LIMIT429Rate limit exceeded
INTERNAL_ERROR500Unexpected server error
TRANSACTION_BUILD_FAILED500Failed to build the swap transaction
UPSTREAM_ERROR502Error from an upstream provider
RPC_FAILURE502Blockchain RPC node error
SERVICE_UNAVAILABLE503Service temporarily unavailable
TIMEOUT504Request timed out
UPSTREAM_TIMEOUT504Upstream provider timed out
For detailed error handling strategies, see the Error Handling Guide.

Handling Responses in Code

import { Hypermid, HypermidError } from "@hypermid/sdk";

const client = new Hypermid({ apiKey: "your-api-key" });

try {
  const response = await client.getQuote({
    fromChain: 1,
    toChain: 42161,
    fromToken: "0x0000000000000000000000000000000000000000",
    toToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
    fromAmount: "100000000000000000",
    fromAddress: "0xYourWalletAddress",
  });

  if (response.error) {
    console.error(`Error [${response.error.code}]: ${response.error.message}`);
    return;
  }

  console.log("Quote:", response.data);
  console.log("Request ID:", response.meta.requestId);
  console.log("Rate limit remaining:", response.meta.rateLimit.remaining);
} catch (err) {
  if (err instanceof HypermidError) {
    console.error("API Error:", err.code, err.message);
  }
  throw err;
}

HTTP Status Codes

Hypermid uses standard HTTP status codes alongside the error.code field:
StatusMeaning
200Success
400Bad request (invalid parameters or validation error)
401Unauthorized (invalid API key)
404Not found (no route found)
429Rate limit exceeded
500Internal server error
502Bad gateway (upstream error)
503Service unavailable
504Gateway timeout