2 min read
Model the responses
interface Product {
id: string;
name: string;
type: 'flex' | 'onetime';
min_amount: number;
max_amount: number;
representative_apr: number;
}
interface ApiError {
error: { type: string; code: string; message: string; request_id: string };
}
async function listProducts(base: string): Promise<Product[]> {
const res = await fetch(`${base}/products`);
const body = await res.json();
if (!res.ok) throw new Error((body as ApiError).error.code);
return (body as { data: Product[] }).data;
}
Generate types from the schema
If you consume many endpoints, generate types from the published OpenAPI description rather than hand-writing them, so your client stays in lockstep with the API contract.
Frequently asked questions
Hand-write or generate types?
Hand-write for one or two endpoints; generate from the OpenAPI schema once you use several, so types never drift from the contract.
How do I type the error path?
Model the envelope as an ApiError interface and narrow on it in your error handler, so error.code is fully typed.
Related reading

Quickstart: call the Credicorp public API from Node.js
Node 18+ ships a global fetch, so you can call the Credicorp public API with zero dependencies. This…
Read →
Quickstart: handle Credicorp API error responses
Every Credicorp API error uses the same envelope: { error: { type, code, message, request_id } }. Branch on…
Read →
Quickstart: use the Credicorp public API in Next.js
Here is the idiomatic way to call the Credicorp public API from Next.js. Fetch the product catalogue, cache…
Read →
Quickstart: list Credicorp business-finance products
GET /public/v1/products returns the live catalogue of Credicorp business-finance products. Each item carries…
Read →Funding for UK limited companies
Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.