Documentation
DeepSeek & Codex SDK
Two worked examples that call the real API to verify and issue a credential.
What this page is
Two worked examples that call the real API — one with DeepSeek, one with Codex. Both are runnable as written against https://api.badgebeacon.com once you set the two placeholder keys: your DeepSeek/OpenAI key and a BadgeBeacon API key from Operations → API Keys. Never commit a real key.
DeepSeek — decide with the model, issue with the API
DeepSeek picks the tool; your code executes it against the real API. The issue call uses the X-API-Key header — an API key is not a Bearer token.
import json
import os
import requests
from openai import OpenAI
DEEPSEEK_API_KEY = os.environ["DEEPSEEK_API_KEY"] # your DeepSeek key
BADGEBEACON_API_KEY = os.environ["BADGEBEACON_API_KEY"] # Operations > API Keys
BADGEBEACON_HOST = "https://api.badgebeacon.com/api"
client = OpenAI(api_key=DEEPSEEK_API_KEY, base_url="https://api.deepseek.com")
tools = [{
"type": "function",
"function": {
"name": "badgebeacon_issue",
"description": "Issue a BadgeBeacon certificate to a graduate",
"parameters": {
"type": "object",
"properties": {
"templateId": {"type": "integer"},
"holderName": {"type": "string"},
"holderEmail": {"type": "string"},
},
"required": ["templateId", "holderName"],
},
},
}]
def issue_certificate(template_id: int, holder_name: str, holder_email: str) -> dict:
r = requests.post(
f"{BADGEBEACON_HOST}/certificates/issue",
headers={"X-API-Key": BADGEBEACON_API_KEY, "Content-Type": "application/json"},
json={"templateId": template_id,
"recipients": [{"holderName": holder_name, "holderEmail": holder_email}]},
timeout=30,
)
r.raise_for_status()
return r.json()
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user",
"content": "Maya Chen finished the course. Issue her certificate (template 1)."}],
tools=tools,
)
call = response.choices[0].message.tool_calls[0]
args = json.loads(call.function.arguments)
created = issue_certificate(args["templateId"], args["holderName"], args.get("holderEmail", ""))
print("Issued:", created["created"][0]["code"])
print("Verify at: https://api.badgebeacon.com/api/verify?code=" + created["created"][0]["code"])}
Codex — verify first, then issue
The same flow in TypeScript: verify an existing credential through the public endpoint, then let the model decide and issue through the API.
import OpenAI from "openai";
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const BADGEBEACON_API_KEY = process.env.BADGEBEACON_API_KEY; // Operations > API Keys
const BADGEBEACON_HOST = "https://api.badgebeacon.com/api";
async function verify(code: string) {
const res = await fetch(`${BADGEBEACON_HOST}/verify?code=${code}`);
const data = await res.json();
console.log(code, "->", data.found ? data.certificate.status : "not found",
"| signature valid:", data.certificate.signatureValid);
return data;
}
async function issue(templateId: number, holderName: string, holderEmail: string) {
const res = await fetch(`${BADGEBEACON_HOST}/certificates/issue`, {
method: "POST",
headers: { "X-API-Key": BADGEBEACON_API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ templateId, recipients: [{ holderName, holderEmail }] }),
});
if (!res.ok) throw new Error(`Issue failed: ${res.status} ${await res.text()}`);
return res.json();
}
const runner = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Maya Chen scored 92/100. Verify her certificate BB-2026-AF3UE5, then issue a new one from template 1 if she passed." }],
tools: [{ type: "function", function: { name: "badgebeacon_issue", description: "Issue a BadgeBeacon certificate", parameters: { type: "object", properties: { templateId: { type: "number" }, holderName: { type: "string" }, holderEmail: { type: "string" } }, required: ["templateId", "holderName"] } } }],
});
await verify("BB-2026-AF3UE5");
const call = runner.choices[0].message.tool_calls?.[0];
if (call) {
const args = JSON.parse(call.function.arguments);
const created = await issue(args.templateId, args.holderName, args.holderEmail);
console.log("Issued:", created.created[0].code);
}Full endpoint list, auth, and rate limits: