Base URL
https://api.coexy.com.br/functions/v1/api
API Key
Todas as requisições devem incluir o headerx-api-key com sua chave de API.
curl https://api.coexy.com.br/functions/v1/api/channels \
-H "x-api-key: crt_pk_sua-chave"
crt_pk_....
Nunca exponha sua API Key no código frontend ou em repositórios públicos. Use variáveis de ambiente.
Erros de autenticação
| Status | Mensagem | Causa |
|---|---|---|
401 | x-api-key header required | Header ausente |
401 | Invalid or revoked API key | Chave inválida ou revogada |
401 | API key expired | Chave com prazo expirado |
402 | subscription_blocked | Assinatura bloqueada por falta de pagamento; regularize na página Plano do painel |
402 | subscription_canceled | Assinatura cancelada; assine um plano na página Plano do painel |
429 | Rate limit exceeded | Excedeu o limite de requisições |
Rate limiting
Quando o limite é excedido, a resposta inclui o headerRetry-After com o número de segundos a aguardar.
if (response.status === 429) {
const retryAfter = response.headers.get('Retry-After')
// aguardar retryAfter segundos antes de tentar novamente
}
Client TypeScript recomendado
class CoexyClient {
private baseUrl = 'https://api.coexy.com.br/functions/v1/api'
private apiKey: string
constructor(apiKey: string) {
this.apiKey = apiKey
}
async request<T>(method: string, path: string, body?: unknown): Promise<T> {
const res = await fetch(`${this.baseUrl}${path}`, {
method,
headers: {
'x-api-key': this.apiKey,
'Content-Type': 'application/json',
},
body: body !== undefined ? JSON.stringify(body) : undefined,
})
if (res.status === 429) {
const retry = res.headers.get('Retry-After') ?? '60'
throw new Error(`Rate limit exceeded. Retry after ${retry}s`)
}
if (res.status === 204) return undefined as T
const json = await res.json()
if (!res.ok) throw new Error(json.error ?? `HTTP ${res.status}`)
return json as T
}
}
const coexy = new CoexyClient(
process.env.COEXY_API_KEY!,
)
Client Python recomendado
import httpx
import os
class CoexyClient:
def __init__(self, api_key: str):
self.base_url = "https://api.coexy.com.br/functions/v1/api"
self.api_key = api_key
def request(self, method: str, path: str, body: dict | None = None) -> dict | None:
r = httpx.request(
method,
f"{self.base_url}{path}",
headers={"x-api-key": self.api_key, "Content-Type": "application/json"},
json=body,
)
if r.status_code == 429:
retry = r.headers.get("Retry-After", "60")
raise Exception(f"Rate limit exceeded. Retry after {retry}s")
if r.status_code == 204:
return None
r.raise_for_status()
return r.json()
coexy = CoexyClient(os.environ["COEXY_API_KEY"])
