API compatível com OpenAI

Documentação da API

A Mangaba AaaS oferece uma API compatível com OpenAI para acessar múltiplos modelos de IA. Use qualquer SDK OpenAI com nossa plataforma.

Base URL
https://mangaba-api.up.railway.app/api/v1

Alta Performance

Respostas rápidas com streaming em tempo real.

32+ Modelos

OpenAI, Anthropic, Google, Meta e mais.

Autenticação

Use Bearer Token com sua API Key em todas as requisições:

curl -X POST https://mangaba-api.up.railway.app/api/v1/chat/completions \
  -H "Authorization: Bearer mk-sua-api-key-aqui" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-4o-mini", "messages": [{"role": "user", "content": "Olá!"}]}'

Segurança

Nunca exponha sua API Key em código frontend ou repositórios públicos. Use variáveis de ambiente.

Providers Suportados

A Mangaba AaaS roteia suas requisições para o melhor provider disponível:

OpenRouter

200+ modelos

Gateway para múltiplos providers com preços competitivos.

Vercel AI Gateway

Enterprise

Gateway unificado da Vercel com observabilidade avançada.

Chat Completions

POST /api/v1/chat/completions

Parâmetros

Parâmetro Tipo Obrigatório Descrição
model string ID do modelo (ex: openai/gpt-4o-mini)
messages array Lista de mensagens com role e content
temperature float - Criatividade (0-2, padrão: 0.7)
max_tokens integer - Máximo de tokens na resposta
stream boolean - Ativar streaming SSE

Exemplo Python

from mangaba import MangabaAI

client = MangabaAI(api_key="mk-sua-api-key")

response = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[
        {"role": "system", "content": "Você é um assistente útil."},
        {"role": "user", "content": "Explique Python em 3 frases."}
    ],
    temperature=0.7,
    max_tokens=500
)

print(response.choices[0].message.content)

# Informações de custo (exclusivo Mangaba)
print(f"Custo: ${response.mangaba_usage['total_cost_usd']:.6f}")
print(f"Provider: {response.mangaba_usage['provider_name']}")

Exemplo JavaScript

import MangabaAI from 'mangaba';

const client = new MangabaAI({ apiKey: 'mk-sua-api-key' });

const response = await client.chat.completions.create({
    model: 'openai/gpt-4o-mini',
    messages: [
        { role: 'system', content: 'Você é um assistente útil.' },
        { role: 'user', content: 'Explique JavaScript em 3 frases.' }
    ]
});

console.log(response.choices[0].message.content);
console.log('Custo:', response.mangaba_usage?.total_cost_usd);

Exemplo Go

package main

import (
    "context"
    "fmt"
    "github.com/mangaba-ai/mangaba-go"
)

func main() {
    client := mangaba.NewClient("mk-sua-api-key")
    
    resp, _ := client.Chat.Completions.Create(context.Background(), mangaba.ChatRequest{
        Model: "openai/gpt-4o-mini",
        Messages: []mangaba.Message{
            {Role: "user", Content: "Olá! Como funciona Go?"},
        },
    })
    
    fmt.Println(resp.Choices[0].Message.Content)
}

Exemplo cURL/REST

curl https://mangaba-api.up.railway.app/api/v1/chat/completions \
  -H "Authorization: Bearer mk-sua-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini",
    "messages": [{"role": "user", "content": "Olá!"}]
  }'

Listar Modelos

GET /api/v1/models

Retorna todos os modelos disponíveis com informações de preço.

curl https://mangaba-api.up.railway.app/api/v1/models

Modelos Disponíveis

TNG: DeepSeek R1T2 Chimera (free) Free
tngtech/deepseek-r1t2-chimera:free
In: $0.00000/1K
Out: $0.00000/1K
TNG Tech • 163,840 tokens
Kwaipilot: KAT-Coder-Pro V1 (free) Free
kwaipilot/kat-coder-pro:free
In: $0.00000/1K
Out: $0.00000/1K
Kwaipilot • 256,000 tokens
NVIDIA: Nemotron Nano 12B 2 VL (free) Free
nvidia/nemotron-nano-12b-v2-vl:free
In: $0.00000/1K
Out: $0.00000/1K
NVIDIA • 128,000 tokens
Mistral: Devstral 2 2512 (free) Free
mistralai/devstral-2512:free
In: $0.00000/1K
Out: $0.00000/1K
Mistral • 262,144 tokens
TNG: DeepSeek R1T Chimera (free) Free
tngtech/deepseek-r1t-chimera:free
In: $0.00000/1K
Out: $0.00000/1K
TNG Tech • 163,840 tokens
Z.AI: GLM 4.5 Air (free) Free
z-ai/glm-4.5-air:free
In: $0.00000/1K
Out: $0.00000/1K
Z.AI • 131,072 tokens
TNG: R1T Chimera (free) Free
tngtech/tng-r1t-chimera:free
In: $0.00000/1K
Out: $0.00000/1K
TNG Tech • 163,840 tokens
Amazon: Nova 2 Lite (free) Free
amazon/nova-2-lite-v1:free
In: $0.00000/1K
Out: $0.00000/1K
Amazon • 1,000,000 tokens
AllenAI: Olmo 3 32B Think (free) Free
allenai/olmo-3-32b-think:free
In: $0.00000/1K
Out: $0.00000/1K
AllenAI • 65,536 tokens
Qwen: Qwen3 Coder 480B A35B (free) Free
qwen/qwen3-coder:free
In: $0.00000/1K
Out: $0.00000/1K
Qwen • 262,000 tokens
OpenAI: gpt-oss-20b (free) Free
openai/gpt-oss-20b:free
In: $0.00000/1K
Out: $0.00000/1K
OpenAI • 131,072 tokens
Google: Gemma 3 27B (free) Free
google/gemma-3-27b-it:free
In: $0.00000/1K
Out: $0.00000/1K
Google • 131,072 tokens
Meta: Llama 3.3 70B Instruct (free) Free
meta-llama/llama-3.3-70b-instruct:free
In: $0.00000/1K
Out: $0.00000/1K
Meta • 131,072 tokens
Qwen: Qwen3 235B A22B (free) Free
qwen/qwen3-235b-a22b:free
In: $0.00000/1K
Out: $0.00000/1K
Qwen • 131,072 tokens
Google: Gemini 2.0 Flash Experimental (free) Free
google/gemini-2.0-flash-exp:free
In: $0.00000/1K
Out: $0.00000/1K
Google • 1,048,576 tokens
Nex AGI: DeepSeek V3.1 Nex N1 (free) Free
nex-agi/deepseek-v3.1-nex-n1:free
In: $0.00000/1K
Out: $0.00000/1K
Nex AGI • 131,072 tokens
Meituan: LongCat Flash Chat (free) Free
meituan/longcat-flash-chat:free
In: $0.00000/1K
Out: $0.00000/1K
Meituan • 131,072 tokens
Tongyi DeepResearch 30B A3B (free) Free
alibaba/tongyi-deepresearch-30b-a3b:free
In: $0.00000/1K
Out: $0.00000/1K
Alibaba • 131,072 tokens
Venice: Uncensored (free) Free
cognitivecomputations/dolphin-mistral-24b-venice-edition:free
In: $0.00000/1K
Out: $0.00000/1K
Cognitive Computations • 32,768 tokens
Arcee AI: Trinity Mini (free) Free
arcee-ai/trinity-mini:free
In: $0.00000/1K
Out: $0.00000/1K
Arcee AI • 131,072 tokens
Mistral: Mistral 7B Instruct (free) Free
mistralai/mistral-7b-instruct:free
In: $0.00000/1K
Out: $0.00000/1K
Mistral • 32,768 tokens
Nous: Hermes 3 405B Instruct (free) Free
nousresearch/hermes-3-llama-3.1-405b:free
In: $0.00000/1K
Out: $0.00000/1K
Nous Research • 131,072 tokens
NVIDIA: Nemotron Nano 9B V2 (free) Free
nvidia/nemotron-nano-9b-v2:free
In: $0.00000/1K
Out: $0.00000/1K
NVIDIA • 128,000 tokens
OpenAI: gpt-oss-120b (free) Free
openai/gpt-oss-120b:free
In: $0.00000/1K
Out: $0.00000/1K
OpenAI • 131,072 tokens
Mistral: Mistral Small 3.1 24B (free) Free
mistralai/mistral-small-3.1-24b-instruct:free
In: $0.00000/1K
Out: $0.00000/1K
Mistral • 128,000 tokens
MoonshotAI: Kimi K2 0711 (free) Free
moonshotai/kimi-k2:free
In: $0.00000/1K
Out: $0.00000/1K
MoonshotAI • 32,768 tokens
Meta: Llama 3.2 3B Instruct (free) Free
meta-llama/llama-3.2-3b-instruct:free
In: $0.00000/1K
Out: $0.00000/1K
Meta • 131,072 tokens
Qwen: Qwen3 4B (free) Free
qwen/qwen3-4b:free
In: $0.00000/1K
Out: $0.00000/1K
Qwen • 40,960 tokens
Google: Gemma 3 12B (free) Free
google/gemma-3-12b-it:free
In: $0.00000/1K
Out: $0.00000/1K
Google • 32,768 tokens
Google: Gemma 3n 2B (free) Free
google/gemma-3n-e2b-it:free
In: $0.00000/1K
Out: $0.00000/1K
Google • 8,192 tokens
Google: Gemma 3 4B (free) Free
google/gemma-3-4b-it:free
In: $0.00000/1K
Out: $0.00000/1K
Google • 32,768 tokens
Google: Gemma 3n 4B (free) Free
google/gemma-3n-e4b-it:free
In: $0.00000/1K
Out: $0.00000/1K
Google • 8,192 tokens

Monitorar Uso

GET /api/v1/usage

Retorna estatísticas de uso e custos da sua API key.

curl https://mangaba-api.up.railway.app/api/v1/usage \
  -H "Authorization: Bearer mk-sua-api-key"

Resposta

{
  "key": {
    "name": "Chave Principal",
    "prefix": "mk-abc1...xyz9",
    "total_requests": 1542,
    "total_tokens_input": 125000,
    "total_tokens_output": 87000,
    "total_cost_usd": 4.75,
    "cost_this_month_usd": 2.30,
    "monthly_budget_usd": 50.00
  },
  "account": {
    "plan": "pro",
    "credits_balance_usd": 45.25,
    "credits_used_this_month_usd": 4.75
  }
}

Testar API Key

POST /api/v1/test

Valida sua API key e retorna informações do usuário e limites.

curl -X POST https://mangaba-api.up.railway.app/api/v1/test \
  -H "Authorization: Bearer mk-sua-api-key"

Health Check

GET /api/v1/health

Verifica status da API e provider ativo.

curl https://mangaba-api.up.railway.app/api/v1/health

Streaming

Use stream: true para receber a resposta em tempo real via SSE:

from mangaba import MangabaAI

client = MangabaAI(api_key="mk-sua-api-key")

stream = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Conte uma história curta"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Códigos de Erro

Código Significado Ação
400 Bad Request Verifique os parâmetros
401 Unauthorized API Key inválida
402 Payment Required Créditos insuficientes
403 Forbidden Modelo não permitido no plano
429 Rate Limited Aguarde e tente novamente
500 Server Error Erro no provider

Rate Limits

Os limites variam de acordo com seu plano:

Free
10
req/minuto
100/dia
Starter
30
req/minuto
1,000/dia
Pro
100
req/minuto
10,000/dia
Enterprise
1,000
req/minuto
100,000/dia

SDKs Oficiais Mangaba

Use nossos SDKs oficiais para uma integração simplificada:

Python

pip install mangaba
from mangaba import MangabaAI
client = MangabaAI(api_key="mk-...")

Node.js

npm install mangaba
import MangabaAI from 'mangaba';
const client = new MangabaAI({ apiKey: 'mk-...' });

Interface Familiar

O SDK MangabaAI usa a mesma interface do OpenAI. Você pode migrar projetos existentes apenas mudando o import!