DGrid AI Gateway
DGrid AI Gateway provides a single, unified API to access 200+ leading AI models. Users can directly plug their own API keys into tools like Claude Code, Codex, and Moltbot (Clawdbot), which dramatically reduces integration complexity and operational costs.
Quickstart
DGrid AI Gateway unifies the interfaces of hundreds of AI models. You don't need to handle compatibility adaptations for different models in your code—with a single API endpoint and a standardized API request format, you can freely switch and access all the hundreds of models provided by DGrid.
The DGrid official SDK is currently under active development—stay tuned for its release. Below are the available temporary request methods to interact with DGrid AI Gateway.
Prerequisites
Before getting started, you need to:
- Obtain a valid
DGRID_API_KEY(Guide). - Ensure your development environment has network access to
https://api.dgrid.ai. - For SDK usage, install the corresponding OpenAI SDK package in your project.
Direct API Request via cURL
You can send a direct HTTP POST request to the DGrid AI Gateway endpoint using cURL.
curl https://api.dgrid.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DGRID_API_KEY" \
-d '{
"model": "openai/gpt-4o",
"messages": [
{
"role": "user",
"content": "What is the meaning of life?"
}
]
}'Using the OpenAI SDK (DGrid Compatible)
DGrid AI Gateway is fully compatible with the OpenAI SDK specification. You only need to modify the baseURL (and fill in the DGRID_API_KEY) to quickly migrate or integrate.
Prerequisite: Install the OpenAI SDK
First, install the OpenAI SDK in your project:
# For TypeScript/Node.js
npm install openai
# For Python
pip install openaiTypeScript Implementation
import OpenAI from 'openai';
// Initialize the OpenAI client with DGrid AI Gateway configuration
const openai = new OpenAI({
baseURL: 'https://api.dgrid.ai/api/v1', // Point to DGrid AI Gateway endpoint
apiKey: '<DGRID_API_KEY>', // Replace with your valid DGrid API key
defaultHeaders: {
'HTTP-Referer': '<YOUR_SITE_URL>', // Optional: Your application's site URL
'X-Title': '<YOUR_SITE_NAME>', // Optional: Your application's name
},
});
// Async function to send chat completion request
async function getChatCompletion() {
try {
const completion = await openai.chat.completions.create({
model: 'openai/gpt-4o', // Specify the target model (DGrid-supported format)
messages: [
{
role: 'user',
content: 'What is the meaning of life?',
},
],
});
// Print the response result
console.log(completion.choices[0].message);
}
main();Python Implementation
from openai import OpenAI
# Initialize the OpenAI client with DGrid AI Gateway configuration
client = OpenAI(
base_url="https://api.dgrid.ai/api/v1", # Point to DGrid AI Gateway endpoint
api_key="<DGRID_API_KEY>", # Replace with your valid DGrid API key
)
completion = client.chat.completions.create(
extra_headers={
"HTTP-Referer": "<YOUR_SITE_URL>", # Optional: Your application's site URL
"X-Title": "<YOUR_SITE_NAME>", # Optional: Your application's name
},
model="openai/gpt-4o", # Specify the target model (DGrid-supported format)
messages=[
{
"role": "user",
"content": "What is the meaning of life?"
}
]
)
# Return and print the response content
print(completion.choices[0].message.content)Additional Notes
- Optional Headers: The
HTTP-RefererandX-Titleheaders are optional, but filling them in helps DGrid better identify your application and provide more optimized service support. - Model Naming Format: The model parameter uses the format
[provider]/[model-name](e.g.,openai/gpt-4o), which is consistent across all DGrid-supported models for easy switching. - SDK Development Update: The official DGrid SDK is under development and will provide more native features and optimized performance—please pay attention to the official DGrid documentation updates for release information.
