# Go & Rust High-Concurrency — API Store Hub

> VI: Gọi https://apistorehub.com/v1 bằng `reqwest` (Rust) hoặc `net/http` (Go) với HTTP/2 keep-alive, connection pool tái sử dụng TLS và SSE parser chịu tải nghìn request/giây.
> EN: Call https://apistorehub.com/v1 from Rust `reqwest` or Go `net/http` using pooled HTTP/2 connections, streaming SSE parsing, and bounded worker concurrency.

- Canonical VI: https://apistorehub.com/vi/tich-hop/go-rust-high-concurrency
- Canonical EN: https://apistorehub.com/en/tich-hop/go-rust-high-concurrency
- Language: Rust / Go
- Runtime: Rust 1.80+ (tokio, reqwest) / Go 1.22+ (net/http)
- Protocol: OpenAI Compatible (/v1/chat/completions)
- Install: `cargo add reqwest tokio serde_json --features reqwest/json,reqwest/stream`
- Auth Env Var: `API_KEY` (prefix `sk-ash-`)

## Step-by-Step Setup
1. Reuse a single process-wide `reqwest::Client` (Rust) or `http.Client` (Go) for TLS and HTTP/2 pooling.
2. Separate `connect_timeout` (5-10s) from full request/stream timeout (90-180s for reasoning).
3. Bound concurrency with `tokio::sync::Semaphore` (Rust) or a semaphore channel (Go).
4. Stream SSE line-by-line on `data: ` frames while ignoring `:` keepalive comment lines.

## Production Code Sample
```
use serde_json::json;
use std::time::Duration;

async fn call_gateway(client: &reqwest::Client, api_key: &str) -> Result<String, reqwest::Error> {
    let resp = client
        .post("https://apistorehub.com/v1/chat/completions")
        .bearer_auth(api_key)
        .timeout(Duration::from_secs(90))
        .json(&json!({
            "model": "deepseek-v4-flash",
            "messages": [{"role": "user", "content": "Return OK"}]
        }))
        .send()
        .await?
        .error_for_status()?;
    let body: serde_json::Value = resp.json().await?;
    Ok(body["choices"][0]["message"]["content"].as_str().unwrap_or_default().to_string())
}
```

## Quick cURL Check
```bash
curl --http2 https://apistorehub.com/v1/chat/completions \
  -H "Authorization: Bearer sk-ash-your_key" \
  -H "Content-Type: application/json" \
  -d '{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"Ping"}]}'
```

## Recommended Models (Live ST Pricing)
| Model | Live Price | Context | Datasheet |
|---|---|---|---|
| `deepseek-v4-flash` | 1,500 ST / 1M tokens | 1M | https://apistorehub.com/llms/models/deepseek-v4-flash.md |
| `gpt-6.1-terra` | 3,400 ST / 1M tokens | 1.1M | https://apistorehub.com/llms/models/gpt-6-1-terra.md |
| `claude-haiku-5-5` | 400 ST / 1M tokens | 200K | https://apistorehub.com/llms/models/claude-haiku-5-5.md |

## FAQ
- **Do I need a third-party SDK in Rust or Go?**: No. Calling `https://apistorehub.com/v1/chat/completions` directly with `reqwest` or `net/http` gives full control over timeouts, pooling, and allocations.
- **What `http.Transport` settings work best in Go?**: Match `MaxIdleConnsPerHost` to your worker concurrency (e.g. 64-256) with `ForceAttemptHTTP2: true`.
- **Does the gateway support HTTP/2 and SSE streaming?**: Yes. Standard HTTP/2 multiplexing and Server-Sent Events streaming are supported end-to-end.
