Framework Recipes
Below are dedicated guides for using Aluvia proxies with popular frameworks like Playwright, Puppeteer, and LangChain. Copy and paste the snippets, then replace your credentials with actual ones from your Aluvia dashboard.
Node.js + Axios​
Make requests through Aluvia proxies using Axios.
const axios = require('axios');
const PROXY_HOST = 'us-mobile-proxy.aluvia.io';
const PROXY_PORT = 10000;
const PROXY_USER = 'your_proxy_username';
const PROXY_PASS = 'your_proxy_password';
(async () => {
try {
const response = await axios.get('https://ifconfig.me', {
proxy: {
host: PROXY_HOST,
port: PROXY_PORT,
auth: {
username: PROXY_USER,
password: PROXY_PASS
}
},
});
console.log('Your IP:', response.data);
} catch (err) {
console.error('Request failed:', err.message);
}
})();
Puppeteer​
Use Aluvia proxies with Puppeteer for browser automation.
const puppeteer = require('puppeteer');
const PROXY_HOST = 'us-mobile-proxy.aluvia.io';
const PROXY_PORT = 10000;
const PROXY_USER = 'your_proxy_username';
const PROXY_PASS = 'your_proxy_password';
(async () => {
const browser = await puppeteer.launch({
headless: true,
args: [`--proxy-server=http=${PROXY_HOST}:${PROXY_PORT}`],
});
const page = await browser.newPage();
await page.authenticate({
username: PROXY_USER,
password: PROXY_PASS,
});
await page.goto('https://ifconfig.me');
console.log('Page title:', await page.title());
await browser.close();
})();
Playwright​
Use Aluvia proxies with Playwright.
const { chromium } = require('playwright');
const PROXY_HOST = 'us-mobile-proxy.aluvia.io';
const PROXY_PORT = 10000;
const PROXY_USER = 'your_proxy_username';
const PROXY_PASS = 'your_proxy_password';
(async () => {
const browser = await chromium.launch({
headless: true,
proxy: {
server: `http://${PROXY_HOST}:${PROXY_PORT}`,
username: PROXY_USER,
password: PROXY_PASS,
},
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://ifconfig.me');
console.log('Page title:', await page.title());
await browser.close();
})();
LangChain (Node.js)​
Integrate Aluvia proxies when making requests with LangChain.
import { ChatOpenAI } from "@langchain/openai";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import fetch from "node-fetch";
const PROXY_HOST = 'us-mobile-proxy.aluvia.io';
const PROXY_PORT = 10000;
const PROXY_USER = 'your_proxy_username';
const PROXY_PASS = 'your_proxy_password';
const customFetch = (url, options = {}) => {
const HttpsProxyAgent = require('https-proxy-agent');
const proxyUrl = `http://${PROXY_USER}:${PROXY_PASS}@${PROXY_HOST}:${PROXY_PORT}`;
const agent = new HttpsProxyAgent(proxyUrl);
return fetch(url, { ...options, agent });
};
const model = new ChatOpenAI({
openAIApiKey: process.env.OPENAI_API_KEY,
fetch: customFetch,
});
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful assistant."],
["human", "Hello!"],
]);
const chain = prompt.pipe(model);
(async () => {
const response = await chain.invoke({});
console.log(response);
})();