# Role of the API Service in Akash Console: Architecture and Implementation

> Discover the API service role in Akash Console. Learn how it centralizes communication, resolves endpoints, and executes type-safe HTTP requests to the Akash API-server.

- Repository: [Akash Network/console](https://github.com/akash-network/console)
- Tags: architecture
- Published: 2026-02-24

---

**The API service in Akash Console serves as the centralized communication layer that resolves network endpoints and executes type-safe HTTP requests to the Akash API-server across Mainnet, Testnet, and Sandbox environments.**

The Akash Console repository contains a sophisticated, multi-layered architecture that standardizes how frontend applications interact with the Akash blockchain network. At its foundation, the API service in Akash Console provides a single source of truth for backend communication, abstracting environment-specific URLs and unifying response handling through generic, Axios-based wrappers. This design ensures that every module—from deployment UIs to analytics dashboards—communicates with the Akash API-server consistently, regardless of whether the code executes in a Node.js server context or a browser environment.

## Core Architecture Components

The API service consists of three complementary layers that separate concerns between URL resolution, low-level HTTP transport, and high-level API interaction.

### ApiUrlService – Network Endpoint Resolution

The **ApiUrlService** class determines the correct base URL for API requests based on the target network. Located in [`apps/stats-web/src/services/api-url/api-url.service.ts`](https://github.com/akash-network/console/blob/main/apps/stats-web/src/services/api-url/api-url.service.ts), this service reads environment variables to distinguish between Mainnet, Testnet, and Sandbox endpoints. It functions identically on both server-side (Node.js) and client-side (Next.js) contexts by accepting the appropriate environment variable mappings.

Consumers supply only a `NetworkId` constant, and the service returns the corresponding base URL. This eliminates hard-coded endpoints throughout the application and centralizes network configuration. A similar implementation exists in [`apps/deploy-web/src/services/api-url/api-url.service.ts`](https://github.com/akash-network/console/blob/main/apps/deploy-web/src/services/api-url/api-url.service.ts) for the Deploy UI.

### HttpService – Low-Level Axios Foundation

At the transport layer, **HttpService** in [`packages/http-sdk/src/http/http.service.ts`](https://github.com/akash-network/console/blob/main/packages/http-sdk/src/http/http.service.ts) extends the Axios class to establish default request configurations. This low-level wrapper applies library-wide settings and provides a protected `extractData` helper method that higher-level services utilize to unwrap response payloads. By inheriting from Axios, HttpService maintains full compatibility with the Axios ecosystem while allowing the Console to inject custom defaults uniformly.

### ApiHttpService – Generic Request Wrapper

Building upon HttpService, **ApiHttpService** in [`packages/http-sdk/src/api-http/api-http.service.ts`](https://github.com/akash-network/console/blob/main/packages/http-sdk/src/api-http/api-http.service.ts) provides thin, generic `GET`, `POST`, and `PATCH` helpers that return raw Axios responses. Its critical contribution is the `extractApiData` method, which automatically extracts the `data` field from the API’s `{ data: … }` envelope structure. This ensures that every consumer receives the actual payload without repetitive destructuring logic. The service supports generic type parameters (`<T>`), enabling compile-time safety and IntelliSense across the codebase.

## Authentication Handling

For operations requiring credentials, the architecture extends ApiHttpService into specialized implementations such as **ApiKeyHttpService** in [`packages/http-sdk/src/api-key/api-key-http.service.ts`](https://github.com/akash-network/console/blob/main/packages/http-sdk/src/api-key/api-key-http.service.ts). This concrete service manages API key lifecycle operations—creation, listing, and deletion—by passing `{ withCredentials: true }` to the underlying HTTP methods. The wrapper ensures that cookies or JWT tokens attach uniformly to requests, centralizing authentication logic rather than scattering it throughout UI components.

## Implementation Examples

### Resolving Base API URLs

To obtain the correct endpoint for a specific network, instantiate ApiUrlService with environment configuration:

```typescript
import { ApiUrlService } from '@/services/api-url/api-url.service';
import { SANDBOX_ID, TESTNET_ID } from '@akashnetwork/chain-sdk/web';

const env = {
  NEXT_PUBLIC_BASE_API_MAINNET_URL: 'https://api.mainnet.akash.network',
  NEXT_PUBLIC_BASE_API_TESTNET_URL: 'https://api.testnet.akash.network',
  NEXT_PUBLIC_BASE_API_SANDBOX_URL: 'https://api.sandbox.akash.network',
};

const urlService = new ApiUrlService(env);
console.log(urlService.getBaseApiUrlFor(TESTNET_ID));
// → https://api.testnet.akash.network

```

### Performing Authenticated Operations

The following example demonstrates API key management using the specialized HTTP service:

```typescript
import { ApiKeyHttpService } from '@akashnetwork/console/packages/http-sdk/src/api-key/api-key-http.service';

const apiKeyService = new ApiKeyHttpService({
  baseURL: 'https://api.testnet.akash.network',
  withCredentials: true,
});

await apiKeyService.createApiKey({ name: 'my-key', scopes: ['read', 'write'] });
const keys = await apiKeyService.getApiKeys();
await apiKeyService.deleteApiKey('abcd-1234-efgh');

```

### Generic HTTP Requests

For direct API communication, use ApiHttpService to handle the response envelope automatically:

```typescript
import { ApiHttpService } from '@akashnetwork/console/packages/http-sdk/src/api-http/api-http.service';

const http = new ApiHttpService({ baseURL: 'https://api.mainnet.akash.network' });
const response = await http.get('/v1/deployments');
const data = http.extractApiData(response);

```

## Summary

- The **ApiUrlService** centralizes network endpoint resolution, ensuring the UI never hard-codes URLs by mapping `NetworkId` values to environment-specific base addresses.
- **HttpService** provides the foundational Axios extension that establishes default configurations and protected data extraction utilities.
- **ApiHttpService** adds generic request methods and automatic unwrapping of the `{ data: … }` response envelope, delivering type-safe payloads to consumers.
- Authentication flows through specialized extensions like **ApiKeyHttpService**, which leverage the underlying layers while uniformly handling credentials via `withCredentials`.
- The entire stack operates identically in Node.js and browser environments, supporting both server-side rendering and client-side execution in Next.js applications.

## Frequently Asked Questions

### What is the primary responsibility of the API service in Akash Console?

The API service acts as the backbone for all communication between the Console's frontend modules and the Akash API-server. It abstracts endpoint selection, standardizes HTTP transport, and ensures type-safe data extraction across Mainnet, Testnet, and Sandbox networks.

### How does ApiUrlService handle different network environments?

ApiUrlService reads environment variables—such as `NEXT_PUBLIC_BASE_API_TESTNET_URL`—to determine the correct base URL for a given `NetworkId`. This allows the same code to target different blockchain environments without conditional logic scattered throughout the application.

### What is the difference between HttpService and ApiHttpService?

HttpService in [`packages/http-sdk/src/http/http.service.ts`](https://github.com/akash-network/console/blob/main/packages/http-sdk/src/http/http.service.ts) is a low-level Axios extension that manages default configurations. ApiHttpService in [`packages/http-sdk/src/api-http/api-http.service.ts`](https://github.com/akash-network/console/blob/main/packages/http-sdk/src/api-http/api-http.service.ts) builds upon it to provide generic request methods and the `extractApiData` utility that unwraps the API's standard response envelope.

### How does the API service handle authentication?

Services requiring authentication, such as ApiKeyHttpService, pass `{ withCredentials: true }` to the base HTTP methods. This ensures cookies or JWT tokens attach uniformly to requests, centralizing credential management within the service layer rather than individual UI components.