Skip to content

Quickstart

From install to your first answer in minutes — in Python, TypeScript, Go, Rust, Java, C#/.NET, Ruby and PHP.

Python

Install the SDK (the CLI ships inside it):

bash
pip install infrai

Activate once, then call any module. Activation is the single onboarding entry: it creates an anonymous account, mints a project key, and grants trial credit.

python
from infrai import infra, ai

infra.activate()              # anonymous account + $2 trial credit, zero-config

reply = ai.chat("Explain React useEffect in one sentence")
print(reply["content"])
print(reply["_metadata"])     # cost_usd, latency_ms, vendor, cache_hit

Choose a China-region model for 0% markup, send an email, or schedule a job — all behind the same key:

python
# China-region model → 0% markup
ai.chat("写一个快速排序", vendor="deepseek")

# Send an email
infra.email.send(to="x@y.com", subject="Hi", body="...")

# Schedule a cron job
infra.cron.create(
    cron_expr="0 9 * * *",
    task="https://api.myapp.com/daily",
    idempotency_key="daily-digest-v1",
)

TypeScript

Install the package:

bash
npm install @infrai/sdk

Create a client with your project key and call a module:

typescript
import { InfraiClient } from "@infrai/sdk";

const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });

const r = await client.ai.chat({ messages: "Explain React useEffect" });
console.log(r.content);
console.log(r.metadata);      // cost_usd, latency_ms, vendor, cache_hit

Stream tokens as they arrive:

typescript
for await (const chunk of client.ai.streamChat({ messages: "Tell me a story" })) {
  process.stdout.write(chunk.delta.content ?? "");
}

More languages — Go, Rust, Java, C#/.NET, Ruby, PHP

These are GA for core calls. Here is a minimal chat completion in each.

Go

bash
go get github.com/infrailab/infrai-go
go
package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/infrailab/infrai-go"
	"github.com/infrailab/infrai-go/modules/ai"
)

func main() {
	c := infrai.New(
		infrai.WithAPIKey(os.Getenv("INFRAI_API_KEY")),
		infrai.WithTimeout(30*time.Second),
	)
	ctx := context.Background()
	res, err := c.AI().Chat(ctx, &ai.ChatRequest{
		Messages: []ai.ChatMessage{{Role: "user", Content: "Why is the sky blue?"}},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(res.Data.Content)
}

Rust

bash
cargo add infrai
rust
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = infrai::Client::builder()
        .api_key(std::env::var("INFRAI_API_KEY")?)
        .build()?;

    let resp = client
        .ai_runtime()
        .chat()
        .user("What is the capital of Japan?")
        .send()
        .await?;

    println!("{:?}", resp.choices);
    Ok(())
}

Java

bash
io.infrailab:infrai-sdk:0.2.0
java
import io.infrailab.Client;
import io.infrailab.Infrai;
import com.fasterxml.jackson.databind.JsonNode;

public class BasicChat {
    public static void main(String[] args) throws Exception {
        Client client = Infrai.builder()
            .apiKey(System.getenv("INFRAI_API_KEY"))
            .build();
        JsonNode resp = client.aiRuntime().chat()
            .user("What is the capital of Japan?")
            .send();
        System.out.println(resp.toPrettyString());
    }
}

Next steps