クイックスタート
Llama 3.1 8Bを十数行でデプロイ。
SDKがジョブの作成、EIP-2612のpermit、createJobトランザクションを処理し、プロバイダーがエンドポイントを立ち上げるまで待機します。
npm install @mzgrid/sdk viem— SDKとviemをインストールBase上のMZG— 「価格 × 最大時間」分のMZGを保有Base上のETH— 入金トランザクションのガス代として少額のETH
deploy.ts
import { CURRENT_TERMS_VERSION, MZGridClient } from "@mzgrid/sdk";
import { createWalletClient, custom } from "viem";
import { base } from "viem/chains";
const wallet = createWalletClient({ chain: base, transport: custom(window.ethereum!) });
// Wallet sign-in requires the Terms of Service version the user has explicitly accepted
const mzg = new MZGridClient({ apiUrl: "https://api.mzgrid.io", walletClient: wallet, termsVersion: CURRENT_TERMS_VERSION });
// 1. Let the scheduler pick the best RTX 4090 by price, reliability and proximity
const created = await mzg.jobs.create({
sku: "rtx4090",
autoSelect: true,
template: "llama-3.1-8b",
maxDurationHours: 4,
});
// 2. Deposit into escrow (EIP-2612 permit + createJob) — deposit = price × 4 h
await mzg.jobs.fund(created, wallet);
// 3. Wait for the OpenAI-compatible endpoint
const { endpointUrl } = await mzg.jobs.waitForEndpoint(created.job.id);
console.log("Ready:", endpointUrl);shell
# Sign in once with your wallet, then create an API key in the dashboard
export MZG_API_KEY="mzg_live_..."
# Browse live offers: cheapest H100 SXM with reliability >= 95
curl -s "https://api.mzgrid.io/v1/market/offers?sku=h100-sxm&minReliability=95&sort=price&limit=5"
# Create a job — returns the escrow parameters to fund on Base
curl -s -X POST "https://api.mzgrid.io/v1/jobs" \
-H "Authorization: Bearer $MZG_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"sku": "h100-sxm",
"autoSelect": true,
"template": "llama-3.3-70b",
"maxDurationHours": 6,
"config": {}
}'
# After funding, report the transaction so the job is dispatched
curl -s -X POST "https://api.mzgrid.io/v1/jobs/$JOB_ID/funded" \
-H "Authorization: Bearer $MZG_API_KEY" \
-H "Content-Type: application/json" \
-d '{"txHash": "0x..."}'poll_job.py
import os, time, requests
API = "https://api.mzgrid.io/v1"
H = {"Authorization": f"Bearer {os.environ['MZG_API_KEY']}"}
# Live GPU catalogue with availability and prices in MZG
for g in requests.get(f"{API}/catalog/gpus").json():
print(f"{g['name']:<24} {g['availableGpus']:>5} free from {g['lowestPrice']} MZG/h")
# Poll a job until its endpoint is ready
job_id = os.environ["JOB_ID"]
while True:
job = requests.get(f"{API}/jobs/{job_id}", headers=H).json()
if job["status"] == "running":
print("Endpoint:", job["endpointUrl"])
break
time.sleep(3)OpenAI互換
既存のクライアントをエンドポイントに向けるだけ。
推論テンプレートはvLLMで動作し、/v1/chat/completions、/v1/completions、/v1/embeddingsを公開します。ベースURLを差し替えるだけで、LangChain、LlamaIndex、OpenAI SDKがそのまま動作します。
chat.py
from openai import OpenAI
# endpointUrl from GET /v1/jobs/:id once status == "running"
client = OpenAI(base_url=f"{endpoint_url}/v1", api_key=os.environ["VLLM_API_KEY"])
resp = client.chat.completions.create(
model="meta-llama/Llama-3.1-8B-Instruct",
messages=[{"role": "user", "content": "Summarise how MZGrid escrow works in two sentences."}],
max_tokens=200,
)
print(resp.choices[0].message.content)stream.ts
import OpenAI from "openai";
const client = new OpenAI({ baseURL: `${endpointUrl}/v1`, apiKey: process.env.VLLM_API_KEY });
const stream = await client.chat.completions.create({
model: "meta-llama/Llama-3.1-8B-Instruct",
messages: [{ role: "user", content: "Write a haiku about idle GPUs." }],
stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");APIリファレンス
エンドポイント一覧。
ベースURL https://api.mzgrid.io/v1。Authorization: Bearer <token | key>で認証します。
公開
- GET
/v1/healthサービスステータス、チェーンID、インデックス済みブロック - GET
/v1/catalog/gpusリアルタイムの空き状況と価格を含むGPUカタログ - GET
/v1/catalog/templatesワークロードテンプレートと推奨GPU - GET
/v1/market/offersライブオファー:sku、リージョン、VRAM、信頼性で絞り込み - GET
/v1/market/offers/:id価格履歴と最近のジョブを含むオファーの詳細 - GET
/v1/network/statsネットワークの累計値と24時間の数値 - GET
/v1/network/timeseriesgpuHours、jobs、providers、mzgSettledなどの日次系列 - GET
/v1/network/regions · /sku-mix · /leaderboard · /activity地域分布、GPU構成、トッププロバイダー、ライブフィード
認証とキー
- POST
/v1/auth/nonceウォレットアドレス用のサインインメッセージを取得 - POST
/v1/auth/verifyEIP-191署名をセッショントークンと交換 - POST
/v1/keysAPIキー(mzg_live_…)を作成 - GET · DELETE
/v1/keys · /v1/keys/:idAPIキーの一覧表示または失効
ジョブとアカウント
- POST
/v1/jobsオファーまたはautoSelectでジョブを作成し、エスクローのパラメーターを返す - POST
/v1/jobs/:id/funded入金トランザクションのハッシュを送信し、コーディネーターがJobFundedを検証 - GET
/v1/jobs · /v1/jobs/:idジョブの一覧、またはステータス・エンドポイント・トランザクションを含む個別ジョブを取得 - GET
/v1/jobs/:id/logs指定タイムスタンプ以降のコンテナログ - POST
/v1/jobs/:id/stop早期停止:使用した秒数分を精算し、残りを返金 - GET
/v1/accountMZG残高、エスクロー額、30日間の支出
Base上のスマートコントラクト
MZGToken、MZGridEscrow、ProviderRegistryはBasescanで検証済みです。すべての関数、イベント、定数はコントラクトリファレンスで確認できます。