Nodecode:   Racket SDK
1 Installation
2 Quickstart
2.1 Streaming (SSE)
2.2 Reasoning Token Budget
3 Constants and Client Construction
default-base-url
default-api-key-env
default-user-agent
model-cyber-v1
model-decide-v1
model-image-v1
anthropic-api-version
nodecode-client
make-nodecode-client
4 Inference, Models, Images, and Usage
list-models
get-model
chat-completion
chat-completion-stream
anthropic-messages
generate-image
decode-image-bytes
account-usage
balance-amount
first-content
first-reasoning
delta-content
delta-reasoning
5 Errors and SSE Utilities
exn:  fail:  nodecode
nodecode-unauthorized?
nodecode-insufficient-balance?
nodecode-rate-limited?
raise-nodecode-error
read-sse-event
call-with-sse-json-stream
6 Streamable HTTP MCP Client
default-mcp-url
mcp-protocol-version
mcp-client?
make-mcp-client
mcp-client-url
mcp-client-session-id
mcp-initialize
mcp-list-tools
mcp-call-tool
mcp-list-resources
mcp-read-resource
mcp-ping
mcp-tool-text
7 Links
9.3

Nodecode: Racket SDK🔗ℹ

Foresight Labs

 (require nodecode) package: nodecode

Zero-dependency Racket client for the Nodecode inference API (Cyber v1, Decide v1, Image v1) and the Streamable HTTP Model Context Protocol (MCP) endpoint, maintained by Foresight Labs (based in the EU, architectural Zero Data Retention).

Built directly on Racket’s standard net/http-client and json libraries with zero third-party package dependencies.

    1 Installation

    2 Quickstart

      2.1 Streaming (SSE)

      2.2 Reasoning Token Budget

    3 Constants and Client Construction

    4 Inference, Models, Images, and Usage

    5 Errors and SSE Utilities

    6 Streamable HTTP MCP Client

    7 Links

1 Installation🔗ℹ

Install from the Racket Package Catalog:

raco pkg install nodecode

Or install directly from source:

raco pkg install https://github.com/nodecode-ai/nodecode-racket.git

2 Quickstart🔗ℹ

Create an API key at nodecode.ai/account/keys and export NODECODE_API_KEY. See the Cyber v1 API quickstart for request parameters and wire formats.

(require nodecode)
 
(define client (make-nodecode-client))
 
(define resp
  (chat-completion
   client
   (list (hasheq 'role "user"
                 'content "22/tcp and 8080/tcp are open. What next, in order?"))
   #:model model-cyber-v1
   #:max-tokens 600))
 
(displayln (first-reasoning resp))
(displayln (first-content resp))

2.1 Streaming (SSE)🔗ℹ

(require nodecode)
 
(define client (make-nodecode-client))
 
(define summary
  (chat-completion-stream
   client
   (list (hasheq 'role "user"
                 'content "Audit this Dockerfile for privilege escalation."))
   (lambda (chunk)
     (define txt (delta-content chunk))
     (when txt (display txt) (flush-output)))
   #:model model-cyber-v1
   #:max-tokens 1024))

2.2 Reasoning Token Budget🔗ℹ

Cyber v1 reasons before producing its final answer, and #:max-tokens covers both thinking and final output. Passing a very small limit (such as 100) can exhaust the budget during reasoning and return empty content with "length" as the finish reason. Allocate at least a few hundred tokens.

3 Constants and Client Construction🔗ℹ

Default Nodecode inference API base URL ("https://api.nodecode.ai/v1").

Default environment variable read by make-nodecode-client ("NODECODE_API_KEY").

Default User-Agent header sent with requests ("nodecode-racket/0.1.0").

Model identifier for Cyber v1 ("nodecode-cyber-v1"), an abliterated security reasoning model with a 1M-token context window.

Model identifier for Decide v1 ("nodecode-decide-v1"). See Models and pricing.

Model identifier for Image v1 ("nodecode-image-v1").

Default anthropic-version header sent by anthropic-messages ("2023-06-01").

struct

(struct nodecode-client (api-key base-url user-agent))

  api-key : (or/c string? #f)
  base-url : string?
  user-agent : string?
Immutable configuration struct representing a Nodecode API client.

procedure

(make-nodecode-client [#:api-key api-key 
  #:base-url base-url 
  #:user-agent user-agent]) 
 → nodecode-client?
  api-key : (or/c string? #f) = #f
  base-url : string? = default-base-url
  user-agent : string? = default-user-agent
Creates a nodecode-client. When api-key is #f, reads default-api-key-env. Public catalog calls such as list-models work without an API key.

4 Inference, Models, Images, and Usage🔗ℹ

procedure

(list-models client) → jsexpr?

  client : nodecode-client?
Fetches GET /v1/models, returning live model metadata, context limits, and current pricing. Works without an API key and costs nothing. See Models.

procedure

(get-model client model-id) → jsexpr?

  client : nodecode-client?
  model-id : string?
Fetches GET /v1/models/<model-id>.

procedure

(chat-completion client    
  messages    
  [#:model model    
  #:max-tokens max-tokens    
  #:temperature temperature    
  #:top-p top-p    
  #:stop stop    
  #:tools tools    
  #:tool-choice tool-choice    
  #:extra extra]) → jsexpr?
  client : nodecode-client?
  messages : (listof hash?)
  model : string? = model-cyber-v1
  max-tokens : (or/c exact-positive-integer? #f) = #f
  temperature : (or/c real? #f) = #f
  top-p : (or/c real? #f) = #f
  stop : (or/c string? (listof string?) #f) = #f
  tools : (or/c (listof hash?) #f) = #f
  tool-choice : (or/c string? hash? #f) = #f
  extra : hash? = (hasheq)
Calls POST /v1/chat/completions using OpenAI-compatible Bearer authentication and returns the parsed JSON response hash.

procedure

(chat-completion-stream client    
  messages    
  on-chunk    
  [#:model model    
  #:max-tokens max-tokens    
  #:temperature temperature    
  #:top-p top-p    
  #:stop stop    
  #:tools tools    
  #:tool-choice tool-choice    
  #:extra extra]) → hash?
  client : nodecode-client?
  messages : (listof hash?)
  on-chunk : (-> jsexpr? any)
  model : string? = model-cyber-v1
  max-tokens : (or/c exact-positive-integer? #f) = #f
  temperature : (or/c real? #f) = #f
  top-p : (or/c real? #f) = #f
  stop : (or/c string? (listof string?) #f) = #f
  tools : (or/c (listof hash?) #f) = #f
  tool-choice : (or/c string? hash? #f) = #f
  extra : hash? = (hasheq)
Streams POST /v1/chat/completions with 'stream #t, invoking on-chunk for each parsed Server-Sent Event JSON frame until "[DONE]". Returns an aggregated summary hash with keys 'id, 'model, 'content, 'reasoning, 'finish-reason, 'usage, and 'chunks.

procedure

(anthropic-messages client    
  messages    
  [#:model model    
  #:max-tokens max-tokens    
  #:system system    
  #:temperature temperature    
  #:extra extra]) → jsexpr?
  client : nodecode-client?
  messages : (listof hash?)
  model : string? = model-cyber-v1
  max-tokens : exact-positive-integer? = 1024
  system : (or/c string? (listof hash?) #f) = #f
  temperature : (or/c real? #f) = #f
  extra : hash? = (hasheq)
Calls POST /v1/messages using Anthropic Messages API headers (x-api-key and anthropic-version: 2023-06-01).

procedure

(generate-image client    
  prompt    
  [#:model model    
  #:size size    
  #:n n    
  #:response-format response-format    
  #:seed seed    
  #:extra extra]) → jsexpr?
  client : nodecode-client?
  prompt : string?
  model : string? = model-image-v1
  size : (or/c string? #f) = #f
  n : (or/c exact-positive-integer? #f) = #f
  response-format : string? = "b64_json"
  seed : (or/c exact-integer? #f) = #f
  extra : hash? = (hasheq)
Calls POST /v1/images/generations with model-image-v1 by default.

procedure

(decode-image-bytes image-hash) → bytes?

  image-hash : hash?
Base64-decodes the 'b64_json field of an image item returned by generate-image.

procedure

(account-usage client) → jsexpr?

  client : nodecode-client?
Fetches GET /v1/usage, reporting remaining plan allowance, prepaid credit balance in micros, and running concurrency slots. Costs nothing. See Pricing.

procedure

(balance-amount micros) → inexact-real?

  micros : exact-integer?
Converts prepaid credit micro-units (1,000,000 micros = 1.00 major currency unit) to an inexact real amount.

procedure

(first-content resp) → (or/c string? #f)

  resp : any/c
Extracts the first assistant text response from either an OpenAI-compatible chat completion or an Anthropic Messages response.

procedure

(first-reasoning resp) → (or/c string? #f)

  resp : any/c
Extracts the first reasoning trace ('reasoning or 'reasoning_content, or Anthropic "thinking" blocks) from a response.

procedure

(delta-content chunk) → (or/c string? #f)

  chunk : any/c
Extracts the incremental assistant text delta from a streaming SSE chunk.

procedure

(delta-reasoning chunk) → (or/c string? #f)

  chunk : any/c
Extracts the incremental reasoning delta from a streaming SSE chunk.

5 Errors and SSE Utilities🔗ℹ

struct

(struct exn:fail:nodecode exn:fail (status
    code
    error-type
    request-id
    refill
    body))
  status : exact-nonnegative-integer?
  code : any/c
  error-type : (or/c string? #f)
  request-id : (or/c string? #f)
  refill : any/c
  body : string?
Structured exception raised on non-2xx HTTP responses or MCP JSON-RPC error frames, preserving HTTP status, request ID, and structured 'refill metadata on HTTP 402 responses.

procedure

(nodecode-unauthorized? v) → boolean?

  v : any/c
Returns #t if v is an exn:fail:nodecode with HTTP status 401.

procedure

(nodecode-insufficient-balance? v) → boolean?

  v : any/c
Returns #t if v is an exn:fail:nodecode with HTTP status 402.

procedure

(nodecode-rate-limited? v) → boolean?

  v : any/c
Returns #t if v is an exn:fail:nodecode with HTTP status 429.

procedure

(raise-nodecode-error status    
  body    
  [#:request-id request-id]) → any
  status : exact-nonnegative-integer?
  body : string?
  request-id : (or/c string? #f) = #f
Parses an error response body and raises exn:fail:nodecode.

procedure

(read-sse-event in) → (or/c (hash/c symbol? string?) #f)

  in : input-port?
Reads one Server-Sent Event frame from in, returning #f on EOF.

procedure

(call-with-sse-json-stream in on-chunk) → void?

  in : input-port?
  on-chunk : (-> any/c any)
Streams JSON-encoded SSE data: frames from in into on-chunk until EOF or "[DONE]".

6 Streamable HTTP MCP Client🔗ℹ

 (require nodecode/mcp) package: nodecode

Streamable HTTP JSON-RPC 2.0 client targeting the live Nodecode MCP endpoint (https://nodecode.ai/mcp) or any Streamable HTTP MCP server. All bindings below are also re-exported by nodecode.

(require nodecode/mcp)
 
(define conn (make-mcp-client))
(define info (mcp-initialize conn))
(define tools (mcp-list-tools conn))
(define models (mcp-call-tool conn "list_models"))
(displayln (mcp-tool-text models))

Default Streamable HTTP MCP endpoint ("https://nodecode.ai/mcp").

MCP protocol version advertised during mcp-initialize ("2025-03-26").

procedure

(mcp-client? v) → boolean?

  v : any/c
Predicate for MCP client handles created by make-mcp-client.

procedure

(make-mcp-client [#:url url    
  #:api-key api-key    
  #:user-agent user-agent]) → mcp-client?
  url : string? = default-mcp-url
  api-key : (or/c string? #f) = #f
  user-agent : string? = "nodecode-racket/0.1.0"
Creates a Streamable HTTP MCP client. Tracks Mcp-Session-Id headers across requests.

procedure

(mcp-client-url conn) → string?

  conn : mcp-client?
Returns the endpoint URL of conn.

procedure

(mcp-client-session-id conn) → (or/c string? #f)

  conn : mcp-client?
Returns the active Mcp-Session-Id negotiated with the server, or #f if none was set.

procedure

(mcp-initialize conn    
  [#:client-name client-name    
  #:client-version client-version]) → jsexpr?
  conn : mcp-client?
  client-name : string? = "nodecode-racket"
  client-version : string? = "0.1.0"
Sends the MCP initialize handshake and returns the server result object.

procedure

(mcp-list-tools conn) → jsexpr?

  conn : mcp-client?
Sends tools/list and returns the server’s tool catalog.

procedure

(mcp-call-tool conn name [arguments]) → jsexpr?

  conn : mcp-client?
  name : string?
  arguments : hash? = (hasheq)
Invokes a named MCP tool via tools/call.

procedure

(mcp-list-resources conn) → jsexpr?

  conn : mcp-client?
Sends resources/list.

procedure

(mcp-read-resource conn uri) → jsexpr?

  conn : mcp-client?
  uri : string?
Reads a resource via resources/read.

procedure

(mcp-ping conn) → jsexpr?

  conn : mcp-client?
Sends an MCP ping request.

procedure

(mcp-tool-text result) → (or/c string? #f)

  result : any/c
Concatenates all "text" content blocks from an mcp-call-tool result.

7 Links🔗ℹ