OutLayer Documentation

Web2 Integration

Call OutLayer from your web apps, mobile apps, APIs, and backend services via HTTPS. Every execution runs in a TEE and produces cryptographic attestation — you get verifiable proofs of exactly what code ran with what inputs.

Blockchain-grade security, Web2 simplicity: No blockchain knowledge required. Just HTTP calls with stablecoin payments, but with full verifiability via Intel TDX attestation.

For NEAR smart contracts see NEAR Integration — use yield/resume mechanism with NEAR token payments.

Why Web2 Integration?#

Sub-Second Response

Direct HTTPS calls with instant response. No blockchain finalization delays. Execution time depends only on your WASM code complexity.

💵

USDC Payments

Pay with USDC via prepaid Payment Keys. No gas fees per API call. One tx to create/top-up a key, one to withdraw balance.

🔐

TEE Attestation

Every execution produces cryptographic proof (Intel TDX attestation). Verify that exact code ran with exact inputs — no trust required.

💰

Monetize Your API

Earn USD when users call your project. Set your own prices, receive payments directly. No middlemen, no revenue share.

Quick Start#

1

Create Project

Go to /projects → "New Project" → Enter GitHub URL or WASM file.

Detailed guide →
2

Create Payment Key

Go to /payment-keys → Create key with USD balance (e.g., $10).

Payment Keys documentation →
3

Call Your Project

Make HTTP POST request with your Payment Key:

curl -X POST https://api.outlayer.io/call/alice.near/my-project \
  -H "X-Payment-Key: alice.near:0:your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{"city": "Tokyo"}'
{
  "status": "success",
  "output": "Weather in Tokyo: 22°C, Partly Cloudy",
  "compute_cost": "15000",
  "job_id": "abc123..."
}

TEE Attestation: Verifiable Execution#

Every OutLayer execution produces a cryptographic attestation from Intel TDX (Trusted Execution Environment). This proves:

  • Code integrity — Exact WASM binary that ran (SHA256 hash)
  • Input integrity — Exact input data received (SHA256 hash)
  • Output integrity — Result was produced by that code with that input
  • Worker identity — Registered TEE worker with verified measurements

Why this matters: Your users can independently verify that your API actually ran the advertised code. No "trust us" — cryptographic proof. View attestations at /executions → "View Attestation".

// Response includes job_id for attestation lookup
const result = await fetch('https://api.outlayer.io/call/alice.near/my-api', {
  method: 'POST',
  headers: { 'X-Payment-Key': 'alice.near:0:secret' },
  body: JSON.stringify({ query: 'data' })
});

const { job_id, output } = await result.json();

// Users can verify attestation at:
// https://outlayer.io/attestation/{job_id}
// Or via API: GET /attestation/{job_id}

Payments & Monetization#

For API Consumers

  • 1. Create Payment Key with USD balance
  • 2. Include X-Payment-Key header in requests
  • 3. Compute costs deducted automatically
  • 4. Optionally tip project owner via X-Attached-Deposit

For API Providers

  • 1. Users pay you via X-Attached-Deposit header
  • 2. Your WASM reads USD_PAYMENT env var
  • 3. Earnings accumulate in your account
  • 4. Withdraw anytime at /earnings
// In your WASM code - check if user paid
let payment: u64 = std::env::var("USD_PAYMENT")
    .unwrap_or_else(|_| "0".to_string())
    .parse()
    .unwrap_or(0);

if payment < 100_000 {  // Require $0.10 minimum
    eprintln!("Payment required: $0.10 minimum");
    std::process::exit(1);
}

// Process paid request...

Environment Variables#

Your WASM code receives context via environment variables:

VariableDescription
OUTLAYER_EXECUTION_TYPE"HTTPS" (for Web2 calls)
NEAR_SENDER_IDPayment Key owner (e.g., "alice.near")
USD_PAYMENTAmount from X-Attached-Deposit (micro-USD)
OUTLAYER_CALL_IDUnique execution ID for this call

Full list: HTTPS API environment variables

API Reference#

HeaderRequiredDescription
X-Payment-KeyYesFormat: owner:nonce:secret
X-Attached-DepositNoUSD micro-units to pay project owner (1M = $1)
X-Compute-LimitNoMax compute budget in USD micro-units

Full API documentation: HTTPS API Reference →

Code Examples#

JavaScript / TypeScript#

async function callOutLayer(project, input, options = {}) {
  const response = await fetch(`https://api.outlayer.io/call/${project}`, {
    method: 'POST',
    headers: {
      'X-Payment-Key': process.env.OUTLAYER_PAYMENT_KEY,
      'Content-Type': 'application/json',
      ...(options.payment && { 'X-Attached-Deposit': options.payment.toString() })
    },
    body: JSON.stringify({ input })
  });

  const result = await response.json();

  if (result.status === 'failed') {
    throw new Error(result.error);
  }

  return {
    output: result.output,
    cost: Number(result.compute_cost) / 1_000_000,  // in USD
    jobId: result.job_id  // for attestation verification
  };
}

// Usage
const weather = await callOutLayer('alice.near/weather-api', { city: 'Tokyo' });
console.log(weather.output);  // "22°C, Partly Cloudy"
console.log(`Cost: $${weather.cost}`);  // "Cost: $0.015"

Python#

import requests
import os

def call_outlayer(project: str, input_data: dict, payment: int = 0) -> dict:
    headers = {"X-Payment-Key": os.environ["OUTLAYER_PAYMENT_KEY"]}
    if payment:
        headers["X-Attached-Deposit"] = str(payment)

    response = requests.post(
        f"https://api.outlayer.io/call/{project}",
        headers=headers,
        json={"input": input_data},
    )
    response.raise_for_status()

    result = response.json()
    if result["status"] == "failed":
        raise Exception(f"Execution failed: {result['error']}")

    return {
        "output": result["output"],
        "cost": int(result["compute_cost"]) / 1_000_000,
        "job_id": result["job_id"]
    }

# Usage
weather = call_outlayer("alice.near/weather-api", {"city": "Tokyo"})
print(weather["output"])

Project Capabilities#

Related Documentation

API & Payments

Building Projects

Verification

Examples