Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/1-basic-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async function main() {
})
});

const data = await response.json();
if (!response.ok) throw new Error("Request failed");
const data = await response.json();
console.log("✅ Response:", data.choices[0].message.content);

// Check budget status
Expand Down
12 changes: 8 additions & 4 deletions examples/2-multiple-providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ async function callOpenAI() {
})
});

const data = await response.json();
if (!response.ok) throw new Error("Request failed");
const data = await response.json();
console.log(" Response:", data.choices[0].message.content);
}

Expand All @@ -53,7 +54,8 @@ async function callAnthropic() {
})
});

const data = await response.json();
if (!response.ok) throw new Error("Request failed");
const data = await response.json();
console.log(" Response:", data.content[0].text);
}

Expand All @@ -71,7 +73,8 @@ async function callGemini() {
}
);

const data = await response.json();
if (!response.ok) throw new Error("Request failed");
const data = await response.json();
console.log(" Response:", data.candidates[0].content.parts[0].text);
}

Expand All @@ -90,7 +93,8 @@ async function callGrok() {
})
});

const data = await response.json();
if (!response.ok) throw new Error("Request failed");
const data = await response.json();
console.log(" Response:", data.choices[0].message.content);
}

Expand Down
3 changes: 2 additions & 1 deletion examples/8-cross-provider-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ async function main() {
}),
});

const data = await response.json();
if (!response.ok) throw new Error("Request failed");
const data = await response.json();
console.log("\nResponse:", data.choices?.[0]?.message?.content);

// Budget is tracked across all providers
Expand Down