This page documents all publicly exposed functions and types in the Raysurfer SDK. Every type is defined down to primitive fields.
High-Level Client
RaysurferClient
Drop-in replacement for Claude Agent SDK’s ClaudeSDKClient.
from raysurfer import RaysurferClient
from claude_agent_sdk import ClaudeAgentOptions
options = ClaudeAgentOptions(
allowed_tools=["Read", "Write", "Bash"],
system_prompt="You are a helpful assistant.",
)
async with RaysurferClient(options) as client:
await client.query("Your task here")
async for msg in client.response():
print(msg)
Constructor Parameters
Python — RaysurferClient(options, workspace_id=None, debug=False):
| Parameter | Type | Description |
|---|
options | ClaudeAgentOptions | Standard Claude Agent SDK options |
workspace_id | string | Workspace ID for per-customer isolation (Pro or Enterprise) |
debug | boolean | Enable debug logging |
TypeScript — new RaysurferClient(options) where options is a single object:
| Parameter | Type | Description |
|---|
allowedTools | string[] | Allowed Claude tools |
systemPrompt | string | System prompt |
model | string | Claude model ID |
workspaceId | string | Workspace ID for per-customer isolation (Pro or Enterprise) |
debug | boolean | Enable debug logging |
Methods
| Method | Description |
|---|
query(prompt) | Send a query with automatic cache retrieval |
response() | Async generator yielding response messages (Python only) |
Low-Level API Client
RaySurfer / AsyncRaySurfer
from raysurfer import RaySurfer, AsyncRaySurfer
# Sync client
client = RaySurfer(api_key="your_api_key")
# Async client
async with AsyncRaySurfer(api_key="your_api_key") as client:
result = await client.search(task="Fetch GitHub repos")
Constructor Options
| Option | Type | Description |
|---|
api_key / apiKey | string | Your Raysurfer API key |
base_url / baseUrl | string | API base URL (optional) |
timeout | number | Request timeout in seconds/ms |
organization_id / organizationId | string | Organization ID for team/enterprise namespacing |
workspace_id / workspaceId | string | Workspace ID for per-customer namespacing (Pro or Enterprise) |
snips_desired / snipsDesired | "company" | "client" | Scope of private snippets |
public_snips / publicSnips | boolean | Include community public snippets |
search
Search for cached code snippets by task description.
result = client.search(
task="Fetch GitHub trending repos",
top_k=5,
min_verdict_score=0.3,
prefer_complete=True,
)
for match in result.matches:
print(f"{match.code_block.name}: {match.score}")
print(f" File: {match.filename}")
print(f" Source: {match.code_block.source[:80]}...")
Parameters
| Parameter | Type | Default | Description |
|---|
task | string | required | Natural language task description (any length) |
top_k / topK | number | 5 | Maximum number of results |
min_verdict_score / minVerdictScore | number | 0.3 | Minimum quality score filter |
prefer_complete / preferComplete | boolean | false | Prefer longer/more complete implementations |
input_schema / inputSchema | object | null | Optional input schema filter |
Queries can be any length, but shorter queries (under 200 characters) give the best accuracy and speed. Longer queries are automatically rephrased into multiple shorter searches and merged, which adds latency and may reduce precision.
LLM prompt augmentation: The legacy convenience method get_code_files() / getCodeFiles() wraps search() and returns an add_to_llm_prompt string. Use search() directly for full control over results.
upload
Upload a code file from an execution for future reuse.
from raysurfer.types import FileWritten
file = FileWritten(path="fetch_repos.py", content="def fetch(): ...")
# Let Raysurfer AI vote (default behavior)
result = client.upload(
task="Fetch GitHub trending repos",
file_written=file,
succeeded=True,
execution_logs="Fetched 10 trending repos successfully",
)
# Or provide your own vote (AI voting is automatically skipped)
result = client.upload(
task="Fetch GitHub trending repos",
file_written=file,
succeeded=True,
user_vote=1, # 1 = thumbs up, -1 = thumbs down
)
print(f"Stored {result.code_blocks_stored} code blocks")
Parameters
| Parameter | Type | Default | Description |
|---|
task | string | required | The task that was executed |
file_written / fileWritten | FileWritten | required | The file created during execution |
succeeded | boolean | required | Whether the task completed successfully |
use_raysurfer_ai_voting / useRaysurferAiVoting | boolean | true | Let Raysurfer AI vote on stored blocks. Ignored when user_vote is provided. |
user_vote / userVote | int | null | null | User-provided vote: 1 for thumbs up, -1 for thumbs down. When provided, AI voting is automatically skipped. |
vote_source / voteSource | "ai" | "human" | null | null | Explicitly sets the vote source. When omitted, user_vote defaults to "human" and AI voting defaults to "ai". |
vote_count / voteCount | int | null | 1 | Number of votes to apply. Useful for pre-seeding community votes. |
execution_logs / executionLogs | string | null | null | Captured stdout/stderr for vote context |
dependencies | dict[str, str] / Record<string, string> | null | Package dependencies with versions (e.g., {"pandas": "2.1.0"}) |
When use_raysurfer_ai_voting is true (the default) and no user_vote is provided, each newly stored code block is automatically evaluated by Raysurfer’s AI. If you provide a user_vote, AI voting is skipped entirely — your vote is applied directly.
upload_bulk_code_snips / uploadBulkCodeSnips
Bulk upload prompts, logs, and code files for sandboxed grading.
from raysurfer.types import FileWritten, LogFile
files = [
FileWritten(path="app.py", content="def main(): ..."),
FileWritten(path="utils.py", content="def helper(): ..."),
]
logs = [
LogFile(path="logs/run.log", content="Task completed", encoding="utf-8"),
]
# Let Raysurfer AI grade each file (default behavior)
result = client.upload_bulk_code_snips(
prompts=["Build a CLI tool", "Add CSV support"],
files_written=files,
log_files=logs,
)
# Or provide your own votes (AI grading is automatically skipped)
result = client.upload_bulk_code_snips(
prompts=["Build a CLI tool", "Add CSV support"],
files_written=files,
log_files=logs,
user_votes={
"app.py": 1, # thumbs up
"utils.py": -1, # thumbs down
},
)
Parameters
| Parameter | Type | Default | Description |
|---|
prompts | string[] | required | Ordered list of raw user prompts |
files_written / filesWritten | FileWritten[] | required | Code files to store and grade |
log_files / logFiles | LogFile[] | null | Log files (any format; use encoding: "base64" for binary) |
use_raysurfer_ai_voting / useRaysurferAiVoting | boolean | true | Let Raysurfer AI grade and vote on stored blocks. Ignored when user_votes is provided. |
user_votes / userVotes | dict[str, int] | null | null | Dict of filename to vote (1 = thumbs up, -1 = thumbs down). When provided, AI grading is automatically skipped. |
vote_source / voteSource | "ai" | "human" | null | null | Explicitly sets the vote source. When omitted, user_votes defaults to "human" and AI voting defaults to "ai". |
vote_count / voteCount | int | null | 1 | Number of votes to apply per file. Useful for pre-seeding community votes. |
delete
Delete a snippet and all its associated data (vectors, retrieval logs, votes).
# Delete by ID
result = client.delete(snippet_id="cb_abc123")
# Or delete by name
result = client.delete(snippet_id="weather_fetcher.py")
print(f"Deleted {result.deleted_count} snippet(s)")
Parameters
| Parameter | Type | Default | Description |
|---|
snippet_id / snippetId | string | required | The ID or name of the snippet to delete |
workspace_id / workspaceId | string | null | Override client-level workspace ID |
vote_code_snip / voteCodeSnip
Vote on whether a cached code snippet was useful. This triggers background voting on the backend.
client.vote_code_snip(
task="Fetch GitHub trending repos",
code_block_id="abc123",
code_block_name="github_fetcher",
code_block_description="Fetches trending repos",
succeeded=True,
)
Voting is triggered automatically by upload when use_raysurfer_ai_voting is true (the default), and also by the high-level RaysurferClient. Use vote_code_snip directly only for voting on cached blocks after reuse.
Response Types
SearchResponse
Returned by search().
| Field | Type | Description |
|---|
matches | SearchMatch[] | Matching code blocks with scoring |
total_found / totalFound | int | Total matches found |
cache_hit / cacheHit | boolean | Whether results were served from cache |
SubmitExecutionResultResponse
Returned by upload().
| Field | Type | Description |
|---|
success | boolean | Whether the operation succeeded |
code_blocks_stored / codeBlocksStored | int | Number of code blocks stored |
message | string | Human-readable status message |
snippet_name / snippetName | string | null | Name assigned to the stored snippet |
BulkExecutionResultResponse
Returned by upload_bulk_code_snips().
| Field | Type | Description |
|---|
success | boolean | Whether the operation succeeded |
code_blocks_stored / codeBlocksStored | int | Number of code blocks stored |
votes_queued / votesQueued | int | Number of votes queued for AI grading |
message | string | Human-readable status message |
status_url / statusUrl | string | null | URL to check grading status (if applicable) |
DeleteResponse
Returned by delete().
| Field | Type | Description |
|---|
success | boolean | Whether the operation succeeded |
deleted_count / deletedCount | int | Number of snippets deleted |
message | string | Human-readable status message |
VoteCodeSnipResponse
Returned by vote_code_snip().
| Field | Type | Description |
|---|
success | boolean | Whether the operation succeeded |
vote_pending / votePending | boolean | Whether the vote is being processed asynchronously |
message | string | Human-readable status message |
Data Types
SearchMatch
A single result from search(). Contains a full CodeBlock plus a relevance score.
| Field | Type | Description |
|---|
code_block / codeBlock | CodeBlock | The matched code block with full source and metadata |
score | float | Overall relevance score (0–1) |
thumbs_up / thumbsUp | int | Total positive votes on this code block |
thumbs_down / thumbsDown | int | Total negative votes on this code block |
filename | string | Generated filename (e.g., "github_fetcher.py") |
language | string | Programming language (e.g., "python", "typescript") |
entrypoint | string | Main function name to call (e.g., "fetch_repos") |
dependencies | dict[str, str] / Record<string, string> | Package name to version (e.g., {"httpx": "0.27.0"}) |
CodeBlock
A stored code block with full metadata. Nested inside SearchMatch.
| Field | Type | Description |
|---|
id | string | Unique identifier (UUID) |
name | string | Human-readable name (e.g., "GitHub Trending Fetcher") |
description | string | What the code does |
source | string | The full source code |
entrypoint | string | Main function/method name |
language | string | Programming language |
language_version / languageVersion | string | null | Language version (e.g., "3.12") |
dependencies | dict[str, str] / Record<string, string> | Package name to version (e.g., {"pandas": "2.1.0"}) |
tags | string[] | Searchable tags (e.g., ["github", "api"]) |
capabilities | string[] | What the code can do (e.g., ["http_requests", "json_parsing"]) |
input_schema / inputSchema | JsonDict / Record<string, JsonValue> | JSON schema describing expected inputs |
output_schema / outputSchema | JsonDict / Record<string, JsonValue> | JSON schema describing outputs |
example_queries / exampleQueries | string[] | null | Example task queries this code is good for |
created_at / createdAt | string | null | ISO 8601 timestamp of creation |
updated_at / updatedAt | string | null | ISO 8601 timestamp of last update |
FileWritten
A file created during agent execution. Used by upload() and upload_bulk_code_snips().
| Field | Type | Description |
|---|
path | string | File path (e.g., "fetch_repos.py") |
content | string | Full file contents as a string |
LogFile
A log file for bulk grading. Used by upload_bulk_code_snips().
| Field | Type | Default | Description |
|---|
path | string | required | File path (e.g., "logs/run.log") |
content | string | required | File contents (plain text or base64-encoded binary) |
encoding | "utf-8" | "base64" | "utf-8" | Content encoding. Use "base64" for binary files. |
content_type / contentType | string | null | null | MIME type (e.g., "application/json") |
Enums
ExecutionState
Technical execution outcome.
| Value | Description |
|---|
COMPLETED | Execution finished successfully |
ERRORED | Execution threw an error |
TIMED_OUT | Execution exceeded time limit |
CANCELLED | Execution was cancelled |
AgentVerdict
Agent’s judgment on execution quality.
| Value | Description |
|---|
THUMBS_UP | Execution was useful |
THUMBS_DOWN | Execution was not useful |
PENDING | Not yet evaluated |
SnipsDesired
Scope of private snippets for retrieval.
| Value | Required Tier | Description |
|---|
company | PRO or ENTERPRISE | Organization-level snippets |
client | PRO or ENTERPRISE | Client workspace snippets (requires workspace_id) |
Exceptions
Both SDKs include built-in retry logic with exponential backoff for transient failures (429, 5xx, network errors). You don’t need to implement your own retry logic for these cases.
RaySurferError
Base exception for all Raysurfer errors.
| Property | Type | Description |
|---|
message | string | Error message |
APIError
Raised when the API returns an error response. Extends RaySurferError.
| Property | Type | Description |
|---|
message | string | Error message |
status_code / statusCode | int | HTTP status code |
AuthenticationError
Raised when the API key is invalid or missing. Extends RaySurferError.
| Property | Type | Description |
|---|
message | string | Error message |
CacheUnavailableError
Raised when the cache backend is unreachable or returns an unexpected error. Extends RaySurferError.
| Property | Type | Description |
|---|
message | string | Error message |
RateLimitError
Raised when the API rate limit is exceeded. The SDK automatically retries with exponential backoff before raising this error. Extends RaySurferError.
| Property | Type | Description |
|---|
message | string | Error message |
retry_after / retryAfter | int | null | Seconds until rate limit resets |
ValidationError
Raised when request validation fails. Extends RaySurferError.
| Property | Type | Description |
|---|
message | string | Error message |
field | string | null | The field that failed validation |