---
title: Go Integration
lastUpdated: '2026-06-22'
nextjs:
  metadata:
    title: Go Integration - Hive Intelligence
    description: Use Hive Intelligence from Go services with net/http, bearer auth, REST execution, tool discovery, and structured crypto data responses.
    alternates:
      canonical: https://www.hiveintelligence.xyz/sdk/go
---


Use Hive from Go services with `net/http`. This guide covers bearer authentication, REST execution, discovery through `GET /api/v1/tools`, and reusable client code for production services that need live crypto market, wallet, DeFi, and security data.

{% ai-doc-actions path="/sdk/go" title="Go Integration" /%}

---

## Quick start

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

const baseURL = "https://mcp.hiveintelligence.xyz"

type ExecuteRequest struct {
	Tool string         `json:"tool"`
	Args map[string]any `json:"args"`
}

func execute(apiKey string, tool string, args map[string]any) (map[string]any, error) {
	body, err := json.Marshal(ExecuteRequest{
		Tool: tool,
		Args: args,
	})
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest(http.MethodPost, baseURL+"/api/v1/execute", bytes.NewReader(body))
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer "+apiKey)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	if resp.StatusCode >= 300 {
		raw, _ := io.ReadAll(resp.Body)
		return nil, fmt.Errorf("hive request failed: %s", raw)
	}

	var result map[string]any
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		return nil, err
	}

	return result, nil
}
```

---

## Reusable client

```go
type HiveClient struct {
	BaseURL string
	APIKey  string
	Client  *http.Client
}

func NewHiveClient(apiKey string) *HiveClient {
	return &HiveClient{
		BaseURL: "https://mcp.hiveintelligence.xyz",
		APIKey:  apiKey,
		Client:  http.DefaultClient,
	}
}

func (c *HiveClient) Execute(tool string, args map[string]any) (map[string]any, error) {
	body, err := json.Marshal(ExecuteRequest{Tool: tool, Args: args})
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest(http.MethodPost, c.BaseURL+"/api/v1/execute", bytes.NewReader(body))
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer "+c.APIKey)

	resp, err := c.Client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var result map[string]any
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		return nil, err
	}

	return result, nil
}
```

---

## Tool discovery

```go
func (c *HiveClient) ListTools(limit int) (map[string]any, error) {
	req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/api/v1/tools?limit=%d", c.BaseURL, limit), nil)
	if err != nil {
		return nil, err
	}

	req.Header.Set("Authorization", "Bearer "+c.APIKey)

	resp, err := c.Client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var result map[string]any
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		return nil, err
	}

	return result, nil
}
```

---

## Example calls

```go
client := NewHiveClient("YOUR_HIVE_API_KEY")

market, _ := client.Execute("get_coins_market_data", map[string]any{
	"vs_currency": "usd",
	"order":       "market_cap_desc",
	"per_page":    5,
})

wallet, _ := client.Execute("alchemy_get_token_balances_by_wallet", map[string]any{
	"address": "0x1234...",
	"network": "eth-mainnet",
})

security, _ := client.Execute("get_token_security", map[string]any{
	"contract_addresses": "0x6982508145454Ce325dDbE47a25d4ec3d2311933",
	"chainId":            "1",
})
```

---

## Production usage

For production services, keep the API key in your secret manager and inject it through the environment at startup. Use a shared `http.Client` with timeouts, cache slow-moving responses such as protocol TVL or token metadata, and log Hive error codes separately from transport errors so retries stay predictable.

---

## Notes

- The current REST payload uses `tool` and `args`.
- Use `GET /api/v1/tools` before hard-coding tool names or parameters.
- Parse non-2xx responses as structured JSON errors before retrying.
- Cache low-volatility responses such as protocol TVL or token metadata to preserve credits.
- Prefer MCP instead of REST when your runtime already supports tool discovery and JSON-RPC.

---

## Related

- [API Integration](/api-integration) - REST endpoint and request envelope
- [Response Formats](/response-formats) - parse `ok`, `data`, `meta`, and error envelopes
- [Rate Limits](/rate-limits) - retry and quota behavior for production services
- [SDK Overview](/sdk) - choose between REST guides and the published TypeScript adapter
