Skip to content

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:

bash
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:

bash
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:

bash
npm install openai

Create quickstart.ts:

typescript
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:

bash
npx tsx quickstart.ts

Use Python

Install the OpenAI SDK:

bash
pip install openai

Create quickstart.py:

python
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:

bash
python3 quickstart.py

Use Go

Install an OpenAI-compatible Go SDK:

bash
go get github.com/sashabaranov/go-openai

Create main.go:

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:

bash
go run main.go

Next Steps

© 2026 DDTokens