SDK Overview
The DgiDgi SDK (@dgidgi/sdk) provides a type-safe, secure way to interact with the DgiDgi API from JavaScript/TypeScript applications.
Key Features
- Type-Safe: Full TypeScript support with 100+ type definitions
- Secure: In-memory token storage (no localStorage), automatic token refresh
- React Integration: 30+ React Query hooks for seamless data fetching
- Streaming: Built-in support for SSE streaming (chat, agent runs)
- Modular: 39 domain-specific resource modules
Installation
pnpm add @dgidgi/sdk
# or
npm install @dgidgi/sdk
# or
yarn add @dgidgi/sdk
Peer Dependencies
{
"react": "^18.0.0",
"@tanstack/react-query": "^5.0.0"
}
Quick Start
1. Initialize the Client
import { createClient, SDKProvider } from "@dgidgi/sdk";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
// Create the SDK client
const client = createClient({
baseURL: "/api/v1", // or "https://api.dgidgi.ai/api/v1"
});
// Create React Query client
const queryClient = new QueryClient();
// Wrap your app
function App() {
return (
<QueryClientProvider client={queryClient}>
<SDKProvider>
<YourApp />
</SDKProvider>
</QueryClientProvider>
);
}
2. Use Hooks in Components
import { useProjects, useChat, useTenant } from "@dgidgi/sdk";
function ProjectList() {
const tenant = useTenant();
const { projects } = useProjects();
if (projects.isLoading) return <div>Loading...</div>;
if (projects.error) return <div>Error: {projects.error.message}</div>;
return (
<ul>
{projects.data?.data.map(project => (
<li key={project.id}>{project.name}</li>
))}
</ul>
);
}
3. Perform Mutations
import { useProjects } from "@dgidgi/sdk";
function CreateProject() {
const { actions: { create } } = useProjects();
const handleCreate = async () => {
await create.mutateAsync({
name: "My Project",
description: "A new project",
});
};
return (
<button onClick={handleCreate} disabled={create.isPending}>
{create.isPending ? "Creating..." : "Create Project"}
</button>
);
}
Architecture
Available Clients
The SDK is the recommended way to interact with DgiDgi from JavaScript/TypeScript. Other clients are also available:
| Client | Package | Use Case |
|---|---|---|
| TypeScript SDK | @dgidgi/sdk | React apps, Node.js, programmatic access |
| CLI | @dgidgi/cli | Terminal workflows, CI/CD pipelines |
| Chrome Extension | @dgidgi/chrome | Quick browser-based agent access |
| Discord Bot | @dgidgi/discord | AI agents in Discord channels |
| REST API | Direct HTTP | Any language, cURL, Postman |
Next Steps
- Authentication - Learn about auth flows
- React Hooks - Explore available hooks
- Resources - Direct API access
- Connectors - Multi-tenant integrations
- Streaming - Real-time data
- Security - Security best practices