Use the DeepSeek API with Node.js and GirtAI
A Node.js server example using the OpenAI SDK and a GirtAI key.
Prepare a server project
Use a supported Node.js LTS version and run npm install openai. Save the example as example.mjs. Set GIRTAI_API_KEY in the server environment, then run node example.mjs.
Keep the key off the browser
Run this example on a server. A frontend environment variable bundled by Vite or another browser build tool is public; it is not a secret store. Route browser requests through your own authenticated backend.
Choose an available model
deepseek-flash is used here. Use GET /v1/models with your GirtAI key to discover the models available to your account. Switching to deepseek-v4-pro changes pricing; consult the price table first.
Handle errors
Catch SDK exceptions in your application. Check the HTTP status and error body, hide secrets from logs, and do not retry 401 or invalid request errors without correcting the configuration.
Example — run on your server
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.GIRTAI_API_KEY,
baseURL: "https://girtai.com/v1",
timeout: 60000,
maxRetries: 0,
});
const response = await client.chat.completions.create({
model: "deepseek-flash",
messages: [{ role: "user", content: "Hello!" }],
max_tokens: 128,
stream: false,
});
console.log(response.choices[0]?.message?.content);