Documentation
¶
Overview ¶
Package zep provides a complete Go client for the Zep AI memory API (https://www.getzep.com) - Threads, Users, Context Templates, the temporal Knowledge Graph, Batch ingestion, Projects, Tasks, and Webhook signature verification.
Domain-driven layout ¶
This is the only file in the root package - it wires together the Client and its transport. Every domain lives in its own package and owns its own types:
thread - Thread, Message, and rolling Summary user - User identity and per-user instructions graph - the temporal Knowledge Graph (Edge, Node, Episode, ...) contexttemplate - custom context-rendering templates project - settings for the current API key/project task - polling for asynchronous operations batch - bulk ingestion jobs webhook - verifying incoming webhook deliveries (no Client needed) apierror - the *Error type returned for non-2xx responses pagination - the generic Iterator used by every list endpoint param - shared *string/*int/*bool builders and setters polling - the shared Await/backoff loop used by task and batch transport - the low-level HTTP execution every domain service uses
Quick start ¶
client, err := zep.NewClient("z_...")
if err != nil {
log.Fatal(err)
}
u, err := client.User.Add(ctx, "user-1", &user.AddParams{
FirstName: zep.String("Ada"),
LastName: zep.String("Lovelace"),
})
t, err := client.Thread.Create(ctx, "thread-1", "user-1", nil)
_, err = client.Thread.AddMessages(ctx, "thread-1", []thread.Message{
{Role: "user", Content: "Hi, I'm Ada."},
}, nil)
ctxBlock, err := client.Thread.GetUserContext(ctx, "thread-1", nil)
Configuration ¶
A Client is built once via NewClient and is safe for concurrent use by multiple goroutines - construct one per API key/project and share it, the same way you would share an http.Client.
Errors ¶
Every method returns a plain Go error. API errors (non-2xx responses) are always of concrete type *Error (an alias for *apierror.Error) and can be inspected with errors.As or the IsNotFound, IsForbidden, etc. helpers. Transport failures (DNS, connection refused, timeouts) are returned as their underlying error, optionally wrapped - use errors.Is / context.DeadlineExceeded as usual.
Pagination ¶
Paginated list endpoints have a corresponding streaming iterator (for example thread.Service.ListAll alongside thread.Service.List) built on the generic [pagination.Iterator] type, which walks every page lazily as you call Next.
Example (Pagination) ¶
package main
import (
"context"
"fmt"
"log"
zep "github.com/iamkanishka/zep-go"
"github.com/iamkanishka/zep-go/thread"
)
func main() {
client, err := zep.NewClient("z_...")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
it := client.Thread.ListAll(ctx, &thread.ListParams{PageSize: zep.Int(100)})
for it.Next(ctx) {
t := it.Item()
fmt.Println(t.ThreadID)
}
if err := it.Err(); err != nil {
log.Fatal(err)
}
}
Output:
Index ¶
- Constants
- Variables
- func Bool(b bool) *bool
- func Float64(f float64) *float64
- func Int(i int) *int
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- func IsRateLimited(err error) bool
- func IsUnauthorized(err error) bool
- func String(s string) *string
- type AwaitParams
- type Client
- type ClientOption
- type Error
- type ErrorReason
Examples ¶
Constants ¶
const ( ErrorReasonBadRequest = apierror.ReasonBadRequest ErrorReasonForbidden = apierror.ReasonForbidden ErrorReasonNotFound = apierror.ReasonNotFound ErrorReasonConflict = apierror.ReasonConflict ErrorReasonUnprocessableEntity = apierror.ReasonUnprocessableEntity ErrorReasonRateLimited = apierror.ReasonRateLimited ErrorReasonInternalServerError = apierror.ReasonInternalServerError ErrorReasonUnknown = apierror.ReasonUnknown )
Known error reasons, derived from the response's HTTP status code.
const DefaultBaseURL = "https://api.getzep.com"
DefaultBaseURL is used when no WithBaseURL option is given.
const Version = "1.0.0"
Version is the current package version, sent as part of the User-Agent header on every request.
Variables ¶
var ErrTimeout = polling.ErrTimeout
ErrTimeout is returned by Await-style methods when the polling deadline elapses before the task/batch reaches a terminal status.
Functions ¶
func IsConflict ¶
IsConflict reports whether err is a *Error with ErrorReasonConflict.
func IsForbidden ¶
IsForbidden reports whether err is a *Error with ErrorReasonForbidden.
func IsNotFound ¶
IsNotFound reports whether err is a *Error with ErrorReasonNotFound.
Example ¶
package main
import (
"context"
"fmt"
"log"
zep "github.com/iamkanishka/zep-go"
)
func main() {
client, err := zep.NewClient("z_...")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
_, err = client.Thread.GetSummary(ctx, "thread-1")
switch {
case zep.IsNotFound(err):
fmt.Println("no summary yet")
case err != nil:
log.Fatal(err)
}
}
Output:
func IsRateLimited ¶
IsRateLimited reports whether err is a *Error with ErrorReasonRateLimited.
func IsUnauthorized ¶
IsUnauthorized reports whether err is a *Error with ErrorReasonUnauthorized.
Types ¶
type AwaitParams ¶
type AwaitParams = polling.AwaitParams
AwaitParams configures the Await methods on the task and batch packages' Service types.
type Client ¶
type Client struct {
// Resource services, each backed by this Client's shared transport.
Thread *thread.Service
User *user.Service
Context *contexttemplate.Service
Graph *graph.Service
Project *project.Service
Task *task.Service
Batch *batch.Service
// contains filtered or unexported fields
}
Client is a configured handle for talking to the Zep API. Build one with NewClient and reuse it - it is safe for concurrent use. Each domain is exposed as a field backed by that domain's own package.
func MustNewClient ¶
func MustNewClient(apiKey string, opts ...ClientOption) *Client
MustNewClient is like NewClient but panics on error. Intended for program initialization (e.g. package-level vars in a main package), where a misconfigured client should fail fast.
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) (*Client, error)
NewClient builds a new Client. apiKey is your Zep project API key; if empty, NewClient looks it up from the ZEP_API_KEY environment variable and returns an error if neither is set.
Example ¶
package main
import (
"log"
zep "github.com/iamkanishka/zep-go"
)
func main() {
client, err := zep.NewClient("z_...")
if err != nil {
log.Fatal(err)
}
_ = client
}
Output:
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client constructed via NewClient.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL overrides the API base URL (default DefaultBaseURL). Useful for testing against a local server or a regional endpoint.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient overrides the underlying http.Client. Use this to customize transport-level behavior (proxies, TLS config, connection pooling) or to inject a test double.
func WithMaxRetries ¶
func WithMaxRetries(n int) ClientOption
WithMaxRetries sets how many times a retriable error (HTTP 429 or 5xx) is retried with exponential backoff before giving up. Default is 2. Pass 0 to disable retries entirely.
func WithReceiveTimeout ¶
func WithReceiveTimeout(d time.Duration) ClientOption
WithReceiveTimeout sets the per-request timeout applied via the underlying http.Client's Timeout field, unless a custom WithHTTPClient is also supplied (in which case that client's own timeout configuration wins).
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent overrides the User-Agent header sent with every request.
type Error ¶
Error represents a non-2xx response from the Zep API. It is a type alias for apierror.Error - see that package for details.
type ErrorReason ¶
ErrorReason classifies an API error by HTTP status code.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apierror defines the error type returned for non-2xx responses from the Zep API, and helpers for classifying/inspecting it.
|
Package apierror defines the error type returned for non-2xx responses from the Zep API, and helpers for classifying/inspecting it. |
|
Package batch implements the Batch domain - the recommended way to load large historical datasets (backfills, document collections, archived conversations, migrations) into Context Graphs.
|
Package batch implements the Batch domain - the recommended way to load large historical datasets (backfills, document collections, archived conversations, migrations) into Context Graphs. |
|
Package contexttemplate implements the Context Template domain: custom context-rendering templates referenced by TemplateID from the thread package's GetUserContext.
|
Package contexttemplate implements the Context Template domain: custom context-rendering templates referenced by TemplateID from the thread package's GetUserContext. |
|
Package graph implements the Graph domain: the temporal knowledge graph - standalone/group/user graphs, episodes, edges, nodes, custom instructions, observations, and folded-in thread summaries.
|
Package graph implements the Graph domain: the temporal knowledge graph - standalone/group/user graphs, episodes, edges, nodes, custom instructions, observations, and folded-in thread summaries. |
|
Package pagination provides a lazy, page-by-page iterator used by every paginated list endpoint across the Zep SDK's domain packages.
|
Package pagination provides a lazy, page-by-page iterator used by every paginated list endpoint across the Zep SDK's domain packages. |
|
Package param provides small shared helpers for building optional request bodies/query strings from pointer fields, and for constructing those pointers in the first place.
|
Package param provides small shared helpers for building optional request bodies/query strings from pointer fields, and for constructing those pointers in the first place. |
|
Package polling provides the shared "poll until terminal status, or time out" loop used by both the task and batch domain packages' Await methods.
|
Package polling provides the shared "poll until terminal status, or time out" loop used by both the task and batch domain packages' Await methods. |
|
Package project implements the Project domain: settings for the API key currently in use.
|
Package project implements the Project domain: settings for the API key currently in use. |
|
Package task implements the Task domain: status polling for asynchronous, long-running Zep operations.
|
Package task implements the Task domain: status polling for asynchronous, long-running Zep operations. |
|
Package testutil provides small shared helpers for testing domain packages against a real httptest.Server, without each domain package needing to depend on the others' tests.
|
Package testutil provides small shared helpers for testing domain packages against a real httptest.Server, without each domain package needing to depend on the others' tests. |
|
Package thread implements the Thread domain: conversation threads, the messages on them, rolling summaries, and the assembled user-context block.
|
Package thread implements the Thread domain: conversation threads, the messages on them, rolling summaries, and the assembled user-context block. |
|
Package transport implements the shared, low-level HTTP execution used by every domain package: request construction, retries with backoff, and JSON encoding/decoding.
|
Package transport implements the shared, low-level HTTP execution used by every domain package: request construction, retries with backoff, and JSON encoding/decoding. |
|
Package user implements the User domain: the identity that threads and graph memory attach to.
|
Package user implements the User domain: the identity that threads and graph memory attach to. |
|
Package webhook verifies incoming Zep webhook deliveries.
|
Package webhook verifies incoming Zep webhook deliveries. |