Skip to content

API v4

API v4 is the new version of the Gaard API. Its contract is a set of protobuf definitions. The OpenAPI specification and the SDKs come from these definitions, so they always agree with the API.

API v3.0 stays supported. You do not have to change your integration. See API v3.0 and its endpoints.

Each RPC of API v4 is available in three forms, on the same host:

ProtocolURLBody
REST JSONhttps://vision.gaard.ai/v4/... (see the OpenAPI specification)JSON
Connecthttps://vision.gaard.ai/gaard.<package>.<Service>/<Method>JSON or protobuf
gRPC-Webhttps://vision.gaard.ai/gaard.<package>.<Service>/<Method>protobuf

For example, the RPC Classify of ClassifyService in the package gaard.classify.v4 is POST /v4/classifications:classify in REST, and POST /gaard.classify.v4.ClassifyService/Classify with Connect. A Connect call with a JSON body must have the header Connect-Protocol-Version: 1.

The JSON field names are in lowerCamelCase, for example idempotencyKey. An enum value is its name, for example "STATE_DONE". A bytes field, for example the clip of Classify, is base64 in JSON.

Download the OpenAPI 3 specification of API v4: openapi.yaml. Use it to generate a client in a language that has no SDK, or to import the API in a tool such as Postman.

API v4 uses the same tokens as API v3.0. Put the token in the Authorization header:

Authorization: Bearer <your-api-token>

Create an API token in the Gaard app at Settings > Platform > Integrations. API v4 does not accept basic authentication.

  • Rate limits. Each call has a cost, and a token and an organization each have a quota for each minute. The response headers RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset give the state of the quota. A call above the quota gets the code resource_exhausted (HTTP 429), with the header Retry-After in seconds.
  • Message size. A request to ClassifyService can be up to 96 MiB in protobuf. In JSON, the clip can be up to 72 MiB before base64. A request to another service can be up to 4 MiB.
  • Deadline. Each RPC has a longest time. A call that takes longer gets the code deadline_exceeded (HTTP 504).

An error has a code, a message, and sometimes details. A REST call gets the HTTP status of the code.

CodeHTTPCause
invalid_argument400A field of the request is not valid. The detail buf.validate.Violations names it.
unauthenticated401The token is missing or not valid.
permission_denied403The token cannot do this call, or cannot see this resource.
not_found404The resource does not exist.
resource_exhausted429The call is above a rate limit. Send it again after the time in Retry-After.
deadline_exceeded504The call took longer than the deadline of the RPC.

The SDKs are generated from the protobuf definitions on the Buf Schema Registry, for TypeScript and Go. Access to the SDKs is on request: contact us to get a registry token. The examples below use this token as BUF_TOKEN, and your Gaard API token as GAARD_TOKEN.

Tell npm where the packages are, in the .npmrc file of your project:

.npmrc
@buf:registry=https://buf.build/gen/npm/v1/
//buf.build/gen/npm/v1/:_authToken=${BUF_TOKEN}

Install the SDK and the Connect runtime:

terminal
npm install @buf/gaard-ai_gaard.bufbuild_es @connectrpc/connect @connectrpc/connect-node

Send a clip and wait for its result:

classify.ts
import { readFileSync } from 'node:fs'
import { createClient } from '@connectrpc/connect'
import { createConnectTransport } from '@connectrpc/connect-node'
import { ClassifyService } from '@buf/gaard-ai_gaard.bufbuild_es/gaard/classify/v4/classify_pb.js'
const transport = createConnectTransport({
baseUrl: 'https://vision.gaard.ai',
httpVersion: '1.1',
interceptors: [
(next) => (req) => {
req.header.set('Authorization', `Bearer ${process.env.GAARD_TOKEN}`)
return next(req)
},
],
})
const client = createClient(ClassifyService, transport)
const res = await client.classify({
content: readFileSync('cam03.mp4'),
filename: 'cam03.mp4',
wait: true,
})
const c = res.classification
console.log(c?.id, c?.state, c?.risk, c?.labels)

Tell Go where the modules are, and give it the registry token:

terminal
export GOPRIVATE=buf.build/gen/go
printf 'machine buf.build\nlogin <your-registry-user>\npassword %s\n' "$BUF_TOKEN" >> ~/.netrc
go get buf.build/gen/go/gaard-ai/gaard/connectrpc/go@latest
go get buf.build/gen/go/gaard-ai/gaard/protocolbuffers/go@latest

Send a clip and wait for its result:

main.go
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"connectrpc.com/connect"
"buf.build/gen/go/gaard-ai/gaard/connectrpc/go/gaard/classify/v4/classifyv4connect"
classifyv4 "buf.build/gen/go/gaard-ai/gaard/protocolbuffers/go/gaard/classify/v4"
)
func main() {
clip, err := os.ReadFile("cam03.mp4")
if err != nil {
log.Fatal(err)
}
client := classifyv4connect.NewClassifyServiceClient(http.DefaultClient, "https://vision.gaard.ai")
req := connect.NewRequest(&classifyv4.ClassifyRequest{
Content: clip,
Filename: "cam03.mp4",
Wait: true,
})
req.Header().Set("Authorization", "Bearer "+os.Getenv("GAARD_TOKEN"))
res, err := client.Classify(context.Background(), req)
if err != nil {
log.Fatal(err)
}
c := res.Msg.GetClassification()
fmt.Println(c.GetId(), c.GetState(), c.GetRisk(), c.GetLabels())
}

The same call in REST JSON. The clip is base64 in the field content:

terminal
curl -X POST https://vision.gaard.ai/v4/classifications:classify \
-H "Authorization: Bearer $GAARD_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"filename\": \"cam03.mp4\", \"wait\": true, \"content\": \"$(base64 < cam03.mp4 | tr -d '\n')\"}"