SDKs & Integrations
Use AICredits with OpenAI SDK (Python/TypeScript), LangChain, Vercel AI SDK, and cURL — a drop-in replacement via base URL change.
Use this page with an AI assistant
Opens a new chat with this docs URL and the correct AICredits base URLs.
AICredits is OpenAI-compatible. Use the standard OpenAI SDK in any language — just change the base URL.
OpenAI SDK (Recommended)
The easiest way to integrate is with the official OpenAI SDK. It works with AICredits out of the box — you only need to change two settings: base_url and api_key.
Python
pip install openaifrom openai import OpenAI
client = OpenAI(
base_url="https://api.aicredits.in/v1",
api_key="sk-your-key-here",
)
# Use any model from any provider
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms."},
],
temperature=0.7,
max_tokens=512,
)
print(response.choices[0].message.content)
# Switch provider by changing the model
response = client.chat.completions.create(
model="anthropic/claude-sonnet-4.5",
messages=[{"role": "user", "content": "Hello Claude!"}],
)
print(response.choices[0].message.content)TypeScript / Node.js
npm install openaiimport OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.aicredits.in/v1",
apiKey: "sk-your-key-here",
});
async function main() {
const response = await client.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Explain quantum computing in simple terms." },
],
temperature: 0.7,
max_tokens: 512,
});
console.log(response.choices[0].message.content);
}
main();Anthropic SDK
You can also use the official Anthropic SDK directly with AICredits. The Anthropic SDK automatically appends /v1/messages to the base URL.
Base URL differs from the OpenAI SDK. When using the Anthropic SDK, set base_url="https://api.aicredits.in" — without /v1. The SDK appends /v1/messages internally. Adding /v1 yourself will result in a /v1/v1/messages path and a 404 error.
import anthropic
client = anthropic.Anthropic(
base_url="https://api.aicredits.in", # no /v1 — SDK adds it
api_key="sk-your-key-here",
)
message = client.messages.create(
model="anthropic/claude-opus-4.5",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude!"}
],
)
print(message.content)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.aicredits.in", // no /v1 — SDK adds it
apiKey: "sk-your-key-here",
});
const message = await client.messages.create({
model: "anthropic/claude-opus-4.5",
max_tokens: 1024,
messages: [
{ role: "user", content: "Hello, Claude!" }
],
});
console.log(message.content);Streaming Examples
Streaming is supported via Server-Sent Events. Set stream: true in your request:
from openai import OpenAI
client = OpenAI(
base_url="https://api.aicredits.in/v1",
api_key="sk-your-key-here",
)
stream = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Write a haiku about coding"}],
stream=True,
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)
print() # Newline after stream endsimport OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.aicredits.in/v1",
apiKey: "sk-your-key-here",
});
const stream = await client.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Write a haiku about coding" }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}
console.log(); // Newline after stream endscurl -N https://api.aicredits.in/v1/chat/completions \
-H "Authorization: Bearer sk-your-key-here" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Write a haiku about coding"}],
"stream": true
}'cURL
For quick testing or scripts, use cURL directly:
# Basic request
curl https://api.aicredits.in/v1/chat/completions \
-H "Authorization: Bearer sk-your-key-here" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Hello!"}]
}'
# Check your balance
curl https://api.aicredits.in/v1/credits \
-H "Authorization: Bearer sk-your-key-here"
# List available models (public endpoint)
curl https://api.aicredits.in/api/modelsLangChain
Use AICredits as a drop-in replacement for the OpenAI provider in LangChain:
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="openai/gpt-4o-mini",
base_url="https://api.aicredits.in/v1",
api_key="sk-your-key-here",
)
response = llm.invoke("What is the meaning of life?")
print(response.content)import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "openai/gpt-4o-mini",
configuration: {
baseURL: "https://api.aicredits.in/v1",
apiKey: "sk-your-key-here",
},
});
const response = await llm.invoke("What is the meaning of life?");
console.log(response.content);Vercel AI SDK
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";
const aicredits = createOpenAI({
baseURL: "https://api.aicredits.in/v1",
apiKey: "sk-your-key-here",
});
const { text } = await generateText({
model: aicredits("openai/gpt-4o-mini"),
prompt: "Write a short poem about APIs.",
});
console.log(text);Environment Variables
Always store your API key in environment variables instead of hardcoding it:
AICREDITS_API_KEY=sk-your-key-here
AICREDITS_BASE_URL=https://api.aicredits.in/v1import os
from openai import OpenAI
client = OpenAI(
base_url=os.environ["AICREDITS_BASE_URL"],
api_key=os.environ["AICREDITS_API_KEY"],
)import OpenAI from "openai";
const client = new OpenAI({
baseURL: process.env.AICREDITS_BASE_URL!,
apiKey: process.env.AICREDITS_API_KEY!,
});Never Commit API Keys
Add .env to your .gitignore file. Never hardcode API keys in source code or commit them to version control.