Quick Start
This page helps you complete your first DDTokens API call. DDTokens is compatible with the OpenAI Chat Completions protocol, so most OpenAI SDK projects only need a different API key and base_url.
Prerequisites
Before you begin, make sure you have:
- A DDTokens account.
- A working API key. If you do not have one, read Create API Key first.
- A terminal that can run commands.
Configure Environment Variables
Set the API key and endpoint in your terminal:
export DDDT_API_KEY="sk-your-key-here"
export DDDT_BASE_URL="https://apiddt.com/v1"Do not put the API key in your code repository. In production, inject it with CI/CD secrets, environment variables, or a secret management system.
Call the API with cURL
Run the following command to send your first message:
curl "$DDDT_BASE_URL/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DDDT_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}'On success, you receive a JSON response containing choices and usage. Use the usage field to reconcile token consumption.
Use TypeScript
Install the OpenAI SDK:
npm install openaiCreate quickstart.ts:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DDDT_API_KEY,
baseURL: process.env.DDDT_BASE_URL ?? "https://apiddt.com/v1",
});
async function main() {
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0]?.message?.content);
}
main();Run it:
npx tsx quickstart.tsUse Python
Install the OpenAI SDK:
pip install openaiCreate quickstart.py:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DDDT_API_KEY"],
base_url=os.environ.get("DDDT_BASE_URL", "https://apiddt.com/v1"),
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)Run it:
python3 quickstart.pyUse Go
Install an OpenAI-compatible Go SDK:
go get github.com/sashabaranov/go-openaiCreate main.go:
package main
import (
"context"
"fmt"
"os"
openai "github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig(os.Getenv("DDDT_API_KEY"))
config.BaseURL = "https://apiddt.com/v1"
client := openai.NewClientWithConfig(config)
response, err := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: "gpt-4o-mini",
Messages: []openai.ChatCompletionMessage{
{Role: openai.ChatMessageRoleUser, Content: "Hello!"},
},
},
)
if err != nil {
panic(err)
}
fmt.Println(response.Choices[0].Message.Content)
}Run it:
go run main.goNext Steps
- Review Model Pricing and choose a suitable model.
- Read Rate Limits and configure retries and rate limiting for production.
- Open a client integration guide to use DDTokens with common AI coding tools.