Relationship Queries
Stream all objects with a user relationship
The Streamed ListObjects API is very similar to the the ListObjects API, with two differences:
- Instead of collecting all objects before returning a response, it streams them to the client as they are collected.
- The number of results returned is only limited by the execution timeout specified in the flag
OPENFGA_LIST_OBJECTS_DEADLINE.
POST
/
stores
/
{store_id}
/
streamed-list-objects
Node.js
const { OpenFgaClient, ConsistencyPreference } = require('@openfga/sdk');
const fgaClient = new OpenFgaClient({
apiUrl: process.env.FGA_API_URL,
storeId: process.env.FGA_STORE_ID,
authorizationModelId: process.env.FGA_MODEL_ID, // Set to the authorization model ID for this request.
});
async function main() {
const body = {
"user": "user:anne",
"relation": "reader",
"type": "document"
};
for await (const item of fgaClient.streamedListObjects(body)) {
console.log(item.object);
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});package main
import (
"context"
"os"
"fmt"
. "github.com/openfga/go-sdk/client"
)
func main() {
fgaClient, err := NewSdkClient(&ClientConfiguration{
ApiUrl: os.Getenv("FGA_API_URL"),
StoreId: os.Getenv("FGA_STORE_ID"),
AuthorizationModelId: os.Getenv("FGA_MODEL_ID"), // Set to the authorization model ID for this request.
})
if err != nil {
panic(err)
}
body := ClientStreamedListObjectsRequest{
User: "user:anne",
Relation: "reader",
Type: "document",
}
stream, err := fgaClient.StreamedListObjects(context.Background()).Body(body).Execute()
if err != nil {
panic(err)
}
defer stream.Close()
for item := range stream.Objects {
fmt.Println(item.Object)
}
if err := <-stream.Errors; err != nil {
panic(err)
}
}using System.Collections.Generic;
using OpenFga.Sdk.Client;
using OpenFga.Sdk.Client.Model;
using OpenFga.Sdk.Model;
using Environment = System.Environment;
using System;
var fgaClient = new OpenFgaClient(new ClientConfiguration() {
ApiUrl = Environment.GetEnvironmentVariable("FGA_API_URL"),
StoreId = Environment.GetEnvironmentVariable("FGA_STORE_ID"),
AuthorizationModelId = Environment.GetEnvironmentVariable("FGA_MODEL_ID"), // Set to the authorization model ID for this request.
});
var body = new ClientListObjectsRequest {
User = "user:anne",
Relation = "reader",
Type = "document",
};
await foreach (var item in fgaClient.StreamedListObjects(body)) {
Console.WriteLine(item.Object);
}import asyncio
import os
from openfga_sdk.client import OpenFgaClient, ClientConfiguration
from openfga_sdk.client.models import ClientListObjectsRequest
async def main():
configuration = ClientConfiguration(
api_url=os.environ.get("FGA_API_URL"),
store_id=os.environ.get("FGA_STORE_ID"),
authorization_model_id=os.environ.get("FGA_MODEL_ID"), # Set to the authorization model ID for this request.
)
async with OpenFgaClient(configuration) as fga_client:
body = ClientListObjectsRequest(
user="user:anne",
relation="reader",
type="document",
)
async for item in fga_client.streamed_list_objects(body=body):
print(item.object)
asyncio.run(main())import dev.openfga.sdk.api.client.OpenFgaClient;
import dev.openfga.sdk.api.configuration.ClientConfiguration;
import dev.openfga.sdk.api.configuration.*;
import dev.openfga.sdk.api.client.model.*;
import dev.openfga.sdk.api.model.*;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
public class Example {
public static void main(String[] args) throws Exception {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL"))
.storeId(System.getenv("FGA_STORE_ID"))
.authorizationModelId(System.getenv("FGA_MODEL_ID")); // Set to the authorization model ID for this request.
var fgaClient = new OpenFgaClient(config);
var body = new ClientListObjectsRequest()
.user("user:anne")
.relation("reader")
.type("document");
fgaClient.streamedListObjects(body, item -> System.out.println(item.getObject())).get();
}
}# Set FGA_API_URL to the URL of your OpenFGA server.
# Set FGA_STORE_ID to your store ID.
# Set FGA_MODEL_ID to your authorization model ID.
# These examples use a server with authentication disabled.
# For authenticated servers, see /docs/getting-started/setup-sdk-client.
curl --no-buffer -X POST "$FGA_API_URL/stores/$FGA_STORE_ID/streamed-list-objects" \
-H "content-type: application/json" \
-d '{
"authorization_model_id": "'"$FGA_MODEL_ID"'",
"user": "user:anne",
"relation": "reader",
"type": "document"
}'{
"error": {
"code": 123,
"details": [
{
"@type": "<string>"
}
],
"message": "<string>"
},
"result": {
"object": "document:roadmap"
}
}{
"code": "validation_error",
"message": "Generic validation error"
}{
"code": "unauthenticated",
"message": "unauthenticated"
}{
"code": "forbidden",
"message": "the principal is not authorized to perform the action"
}{
"code": "undefined_endpoint",
"message": "Endpoint not enabled"
}{
"code": "10",
"message": "transaction conflict"
}{
"code": "throttled_timeout_error",
"message": "timeout due to throttling on complex request"
}{
"code": "internal_error",
"message": "Internal Server Error"
}Path Parameters
Body
application/json
Example:
"reader"
Example:
"document"
Required string length:
1 - 512Example:
"user:anne"
Example:
"01G5JAVJ41T49E9TT3SKVS7X1J"
Controls the consistency preference for this request. Default value is UNSPECIFIED, which has the same behavior as MINIMIZE_LATENCY.
Available options:
UNSPECIFIED, MINIMIZE_LATENCY, HIGHER_CONSISTENCY Example:
"MINIMIZE_LATENCY"
Additional request context used to evaluate any ABAC conditions encountered in the query evaluation.
Show child attributes
Show child attributes
Last modified on September 28, 2026
Was this page helpful?
⌘I
Node.js
const { OpenFgaClient, ConsistencyPreference } = require('@openfga/sdk');
const fgaClient = new OpenFgaClient({
apiUrl: process.env.FGA_API_URL,
storeId: process.env.FGA_STORE_ID,
authorizationModelId: process.env.FGA_MODEL_ID, // Set to the authorization model ID for this request.
});
async function main() {
const body = {
"user": "user:anne",
"relation": "reader",
"type": "document"
};
for await (const item of fgaClient.streamedListObjects(body)) {
console.log(item.object);
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});package main
import (
"context"
"os"
"fmt"
. "github.com/openfga/go-sdk/client"
)
func main() {
fgaClient, err := NewSdkClient(&ClientConfiguration{
ApiUrl: os.Getenv("FGA_API_URL"),
StoreId: os.Getenv("FGA_STORE_ID"),
AuthorizationModelId: os.Getenv("FGA_MODEL_ID"), // Set to the authorization model ID for this request.
})
if err != nil {
panic(err)
}
body := ClientStreamedListObjectsRequest{
User: "user:anne",
Relation: "reader",
Type: "document",
}
stream, err := fgaClient.StreamedListObjects(context.Background()).Body(body).Execute()
if err != nil {
panic(err)
}
defer stream.Close()
for item := range stream.Objects {
fmt.Println(item.Object)
}
if err := <-stream.Errors; err != nil {
panic(err)
}
}using System.Collections.Generic;
using OpenFga.Sdk.Client;
using OpenFga.Sdk.Client.Model;
using OpenFga.Sdk.Model;
using Environment = System.Environment;
using System;
var fgaClient = new OpenFgaClient(new ClientConfiguration() {
ApiUrl = Environment.GetEnvironmentVariable("FGA_API_URL"),
StoreId = Environment.GetEnvironmentVariable("FGA_STORE_ID"),
AuthorizationModelId = Environment.GetEnvironmentVariable("FGA_MODEL_ID"), // Set to the authorization model ID for this request.
});
var body = new ClientListObjectsRequest {
User = "user:anne",
Relation = "reader",
Type = "document",
};
await foreach (var item in fgaClient.StreamedListObjects(body)) {
Console.WriteLine(item.Object);
}import asyncio
import os
from openfga_sdk.client import OpenFgaClient, ClientConfiguration
from openfga_sdk.client.models import ClientListObjectsRequest
async def main():
configuration = ClientConfiguration(
api_url=os.environ.get("FGA_API_URL"),
store_id=os.environ.get("FGA_STORE_ID"),
authorization_model_id=os.environ.get("FGA_MODEL_ID"), # Set to the authorization model ID for this request.
)
async with OpenFgaClient(configuration) as fga_client:
body = ClientListObjectsRequest(
user="user:anne",
relation="reader",
type="document",
)
async for item in fga_client.streamed_list_objects(body=body):
print(item.object)
asyncio.run(main())import dev.openfga.sdk.api.client.OpenFgaClient;
import dev.openfga.sdk.api.configuration.ClientConfiguration;
import dev.openfga.sdk.api.configuration.*;
import dev.openfga.sdk.api.client.model.*;
import dev.openfga.sdk.api.model.*;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
public class Example {
public static void main(String[] args) throws Exception {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL"))
.storeId(System.getenv("FGA_STORE_ID"))
.authorizationModelId(System.getenv("FGA_MODEL_ID")); // Set to the authorization model ID for this request.
var fgaClient = new OpenFgaClient(config);
var body = new ClientListObjectsRequest()
.user("user:anne")
.relation("reader")
.type("document");
fgaClient.streamedListObjects(body, item -> System.out.println(item.getObject())).get();
}
}# Set FGA_API_URL to the URL of your OpenFGA server.
# Set FGA_STORE_ID to your store ID.
# Set FGA_MODEL_ID to your authorization model ID.
# These examples use a server with authentication disabled.
# For authenticated servers, see /docs/getting-started/setup-sdk-client.
curl --no-buffer -X POST "$FGA_API_URL/stores/$FGA_STORE_ID/streamed-list-objects" \
-H "content-type: application/json" \
-d '{
"authorization_model_id": "'"$FGA_MODEL_ID"'",
"user": "user:anne",
"relation": "reader",
"type": "document"
}'{
"error": {
"code": 123,
"details": [
{
"@type": "<string>"
}
],
"message": "<string>"
},
"result": {
"object": "document:roadmap"
}
}{
"code": "validation_error",
"message": "Generic validation error"
}{
"code": "unauthenticated",
"message": "unauthenticated"
}{
"code": "forbidden",
"message": "the principal is not authorized to perform the action"
}{
"code": "undefined_endpoint",
"message": "Endpoint not enabled"
}{
"code": "10",
"message": "transaction conflict"
}{
"code": "throttled_timeout_error",
"message": "timeout due to throttling on complex request"
}{
"code": "internal_error",
"message": "Internal Server Error"
}